drm/vkms: Allow to configure multiple CRTCs

Add a list of CRTCs to vkms_config and helper functions to add and
remove as many CRTCs as wanted.

For backwards compatibility, add one CRTC to the default configuration.

A future patch will allow to attach planes and CRTCs, but for the
moment there are no changes in the way the output is configured.

Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Co-developed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250218101214.5790-10-jose.exposito89@gmail.com
Signed-off-by: Maxime Ripard <mripard@kernel.org>
This commit is contained in:
José Expósito
2025-02-18 11:12:09 +01:00
committed by Maxime Ripard
parent bc5b0d5dcc
commit 600df32dac
4 changed files with 222 additions and 5 deletions

View File

@@ -27,6 +27,16 @@ static struct vkms_config_plane *get_first_plane(struct vkms_config *config)
return NULL;
}
static struct vkms_config_crtc *get_first_crtc(struct vkms_config *config)
{
struct vkms_config_crtc *crtc_cfg;
vkms_config_for_each_crtc(config, crtc_cfg)
return crtc_cfg;
return NULL;
}
struct default_config_case {
bool enable_cursor;
bool enable_writeback;
@@ -46,6 +56,7 @@ static void vkms_config_test_empty_config(struct kunit *test)
KUNIT_EXPECT_STREQ(test, vkms_config_get_device_name(config), "test");
KUNIT_EXPECT_EQ(test, vkms_config_get_num_planes(config), 0);
KUNIT_EXPECT_EQ(test, vkms_config_get_num_crtcs(config), 0);
KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));
@@ -70,6 +81,7 @@ static void vkms_config_test_default_config(struct kunit *test)
const struct default_config_case *params = test->param_value;
struct vkms_config *config;
struct vkms_config_plane *plane_cfg;
struct vkms_config_crtc *crtc_cfg;
int n_primaries = 0;
int n_cursors = 0;
int n_overlays = 0;
@@ -79,8 +91,6 @@ static void vkms_config_test_default_config(struct kunit *test)
params->enable_overlay);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config);
KUNIT_EXPECT_EQ(test, config->writeback, params->enable_writeback);
/* Planes */
vkms_config_for_each_plane(config, plane_cfg) {
switch (vkms_config_plane_get_type(plane_cfg)) {
@@ -101,6 +111,13 @@ static void vkms_config_test_default_config(struct kunit *test)
KUNIT_EXPECT_EQ(test, n_cursors, params->enable_cursor ? 1 : 0);
KUNIT_EXPECT_EQ(test, n_overlays, params->enable_overlay ? 8 : 0);
/* CRTCs */
KUNIT_EXPECT_EQ(test, vkms_config_get_num_crtcs(config), 1);
crtc_cfg = get_first_crtc(config);
KUNIT_EXPECT_EQ(test, vkms_config_crtc_get_writeback(crtc_cfg),
params->enable_writeback);
KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config));
vkms_config_destroy(config);
@@ -149,6 +166,43 @@ static void vkms_config_test_get_planes(struct kunit *test)
vkms_config_destroy(config);
}
static void vkms_config_test_get_crtcs(struct kunit *test)
{
struct vkms_config *config;
struct vkms_config_crtc *crtc_cfg;
struct vkms_config_crtc *crtc_cfg1, *crtc_cfg2;
config = vkms_config_create("test");
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config);
KUNIT_ASSERT_EQ(test, vkms_config_get_num_crtcs(config), 0);
vkms_config_for_each_crtc(config, crtc_cfg)
KUNIT_FAIL(test, "Unexpected CRTC");
crtc_cfg1 = vkms_config_create_crtc(config);
KUNIT_ASSERT_EQ(test, vkms_config_get_num_crtcs(config), 1);
vkms_config_for_each_crtc(config, crtc_cfg) {
if (crtc_cfg != crtc_cfg1)
KUNIT_FAIL(test, "Unexpected CRTC");
}
crtc_cfg2 = vkms_config_create_crtc(config);
KUNIT_ASSERT_EQ(test, vkms_config_get_num_crtcs(config), 2);
vkms_config_for_each_crtc(config, crtc_cfg) {
if (crtc_cfg != crtc_cfg1 && crtc_cfg != crtc_cfg2)
KUNIT_FAIL(test, "Unexpected CRTC");
}
vkms_config_destroy_crtc(config, crtc_cfg2);
KUNIT_ASSERT_EQ(test, vkms_config_get_num_crtcs(config), 1);
vkms_config_for_each_crtc(config, crtc_cfg) {
if (crtc_cfg != crtc_cfg1)
KUNIT_FAIL(test, "Unexpected CRTC");
}
vkms_config_destroy(config);
}
static void vkms_config_test_invalid_plane_number(struct kunit *test)
{
struct vkms_config *config;
@@ -213,13 +267,38 @@ static void vkms_config_test_valid_plane_type(struct kunit *test)
vkms_config_destroy(config);
}
static void vkms_config_test_invalid_crtc_number(struct kunit *test)
{
struct vkms_config *config;
struct vkms_config_crtc *crtc_cfg;
int n;
config = vkms_config_default_create(false, false, false);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config);
/* Invalid: No CRTCs */
crtc_cfg = get_first_crtc(config);
vkms_config_destroy_crtc(config, crtc_cfg);
KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));
/* Invalid: Too many CRTCs */
for (n = 0; n <= 32; n++)
vkms_config_create_crtc(config);
KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));
vkms_config_destroy(config);
}
static struct kunit_case vkms_config_test_cases[] = {
KUNIT_CASE(vkms_config_test_empty_config),
KUNIT_CASE_PARAM(vkms_config_test_default_config,
default_config_gen_params),
KUNIT_CASE(vkms_config_test_get_planes),
KUNIT_CASE(vkms_config_test_get_crtcs),
KUNIT_CASE(vkms_config_test_invalid_plane_number),
KUNIT_CASE(vkms_config_test_valid_plane_type),
KUNIT_CASE(vkms_config_test_invalid_crtc_number),
{}
};