[PATCH v4 17/37] drm/vkms: Introduce config for plane color encoding

Louis Chauvet
2026-04-22T16:49:38Z

VKMS driver supports all the color encoding on planes, but for testing it
can be useful to only advertise few of them. This new configuration
interface will allow configuring the color encoding per planes.

Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/vkms/tests/vkms_config_test.c | 51 +++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_config.c | 32 ++++++++++++++
drivers/gpu/drm/vkms/vkms_config.h | 64 +++++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_plane.c | 15 +++----
4 files changed, 154 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/vkms/tests/vkms_config_test.c b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
index c33fe737678f..a2a3f1a106a3 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_config_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
@@ -192,6 +192,14 @@ static void vkms_config_test_default_config(struct kunit *test)
KUNIT_EXPECT_EQ(test,
vkms_config_plane_get_default_rotation(plane_cfg),
DRM_MODE_ROTATE_0);
+ KUNIT_EXPECT_EQ(test,
+ vkms_config_plane_get_supported_color_encodings(plane_cfg),
+ BIT(DRM_COLOR_YCBCR_BT601) |
+ BIT(DRM_COLOR_YCBCR_BT709) |
+ BIT(DRM_COLOR_YCBCR_BT2020));
+ KUNIT_EXPECT_EQ(test,
+ vkms_config_plane_get_default_color_encoding(plane_cfg),
+ DRM_COLOR_YCBCR_BT601);
}

/* Encoders */
@@ -526,6 +534,48 @@ static void vkms_config_test_valid_plane_rotations(struct kunit *test)
vkms_config_destroy(config);
}

+static void vkms_config_test_valid_plane_color_encoding(struct kunit *test)
+{
+ struct vkms_config *config;
+ struct vkms_config_plane *plane_cfg;
+
+ config = vkms_config_default_create(false, false, false, false);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config);
+
+ plane_cfg = get_first_plane(config);
+
+ /* Valid, all color encoding supported */
+ vkms_config_plane_set_supported_color_encodings(plane_cfg,
+ BIT(DRM_COLOR_YCBCR_BT601) |
+ BIT(DRM_COLOR_YCBCR_BT709) |
+ BIT(DRM_COLOR_YCBCR_BT2020));
+ vkms_config_plane_set_default_color_encoding(plane_cfg, DRM_COLOR_YCBCR_BT601);
+ KUNIT_EXPECT_TRUE(test, vkms_config_valid_plane_color_encoding(config, plane_cfg));
+ KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config));
+
+ /* Invalid, default color encoding is not supported */
+ vkms_config_plane_set_supported_color_encodings(plane_cfg,
+ BIT(DRM_COLOR_YCBCR_BT601) |
+ BIT(DRM_COLOR_YCBCR_BT2020));
+ vkms_config_plane_set_default_color_encoding(plane_cfg, DRM_COLOR_YCBCR_BT709);
+ KUNIT_EXPECT_FALSE(test, vkms_config_valid_plane_color_encoding(config, plane_cfg));
+ KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));
+
+ /* Valid, no supported or color encoding */
+ vkms_config_plane_set_supported_color_encodings(plane_cfg, 0);
+ vkms_config_plane_set_default_color_encoding(plane_cfg, 0);
+ KUNIT_EXPECT_TRUE(test, vkms_config_valid_plane_color_encoding(config, plane_cfg));
+ KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config));
+
+ /* Valid, if no supported color encoding, default is ignored */
+ vkms_config_plane_set_supported_color_encodings(plane_cfg, 0);
+ vkms_config_plane_set_default_color_encoding(plane_cfg, DRM_COLOR_YCBCR_BT601);
+ KUNIT_EXPECT_TRUE(test, vkms_config_valid_plane_color_encoding(config, plane_cfg));
+ KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config));
+
+ vkms_config_destroy(config);
+}
+
static void vkms_config_test_valid_plane_possible_crtcs(struct kunit *test)
{
struct vkms_config *config;
@@ -1049,6 +1099,7 @@ static struct kunit_case vkms_config_test_cases[] = {
KUNIT_CASE(vkms_config_test_invalid_plane_number),
KUNIT_CASE(vkms_config_test_valid_plane_type),
KUNIT_CASE(vkms_config_test_valid_plane_rotations),
+ KUNIT_CASE(vkms_config_test_valid_plane_color_encoding),
KUNIT_CASE(vkms_config_test_valid_plane_possible_crtcs),
KUNIT_CASE(vkms_config_test_invalid_crtc_number),
KUNIT_CASE(vkms_config_test_invalid_encoder_number),
diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c
index 7ae382bdee9d..9faf03c60b8b 100644
--- a/drivers/gpu/drm/vkms/vkms_config.c
+++ b/drivers/gpu/drm/vkms/vkms_config.c
@@ -179,6 +179,25 @@ bool vkms_config_valid_plane_rotation(const struct vkms_config *config,
}
EXPORT_SYMBOL_IF_KUNIT(vkms_config_valid_plane_rotation);

+VISIBLE_IF_KUNIT
+bool vkms_config_valid_plane_color_encoding(const struct vkms_config *config,
+ const struct vkms_config_plane *plane_cfg)
+{
+ struct drm_device *dev = config->dev ? &config->dev->drm : NULL;
+
+ if (vkms_config_plane_get_supported_color_encodings(plane_cfg)) {
+ if ((BIT(vkms_config_plane_get_default_color_encoding(plane_cfg)) &
+ vkms_config_plane_get_supported_color_encodings(plane_cfg)) !=
+ BIT(vkms_config_plane_get_default_color_encoding(plane_cfg))) {
+ drm_info(dev, "Configured default color encoding is not supported by the plane\n");
+ return false;
+ }
+ }
+
+ return true;
+}
+EXPORT_SYMBOL_IF_KUNIT(vkms_config_valid_plane_color_encoding);
+
static bool valid_planes_for_crtc(const struct vkms_config *config,
struct vkms_config_crtc *crtc_cfg)
{
@@ -341,6 +360,9 @@ bool vkms_config_is_valid(const struct vkms_config *config)
vkms_config_for_each_plane(config, plane_cfg) {
if (!vkms_config_valid_plane_rotation(config, plane_cfg))
return false;
+
+ if (!vkms_config_valid_plane_color_encoding(config, plane_cfg))
+ return false;
}

if (!valid_plane_number(config))
@@ -418,6 +440,12 @@ static int vkms_config_show(struct seq_file *m, void *data)
show_bitfield(m, vkms_config_plane_get_default_rotation(plane_cfg),
drm_get_rotation_name);
seq_puts(m, "\n");
+ seq_puts(m, "\tsupported color encoding=");
+ show_bitfield(m, vkms_config_plane_get_supported_color_encodings(plane_cfg),
+ drm_get_color_encoding_name);
+ seq_puts(m, "\n");
+ seq_printf(m, "\tdefault color encoding=%s\n",
+ drm_get_color_encoding_name(vkms_config_plane_get_default_color_encoding(plane_cfg)));
}

vkms_config_for_each_crtc(vkmsdev->config, crtc_cfg) {
@@ -470,6 +498,10 @@ struct vkms_config_plane __must_check *vkms_config_create_plane(struct vkms_conf
vkms_config_plane_set_supported_rotations(plane_cfg,
DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK);
vkms_config_plane_set_default_rotation(plane_cfg, DRM_MODE_ROTATE_0);
+ vkms_config_plane_set_supported_color_encodings(plane_cfg, BIT(DRM_COLOR_YCBCR_BT601) |
+ BIT(DRM_COLOR_YCBCR_BT709) |
+ BIT(DRM_COLOR_YCBCR_BT2020));
+ vkms_config_plane_set_default_color_encoding(plane_cfg, DRM_COLOR_YCBCR_BT601);

xa_init_flags(&plane_cfg->possible_crtcs, XA_FLAGS_ALLOC);

diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
index 449fead7594a..034eaf51b2ca 100644
--- a/drivers/gpu/drm/vkms/vkms_config.h
+++ b/drivers/gpu/drm/vkms/vkms_config.h
@@ -45,6 +45,8 @@ struct vkms_config {
* It can be used to store a temporary reference to a VKMS plane during
* device creation. This pointer is not managed by the configuration and
* must be managed by other means.
+ * @default_color_encoding: Default color encoding that should be used by this plane
+ * @supported_color_encodings: Color encodings that this plane will support
*/
struct vkms_config_plane {
struct list_head link;
@@ -54,6 +56,8 @@ struct vkms_config_plane {
enum drm_plane_type type;
unsigned int default_rotation;
unsigned int supported_rotations;
+ enum drm_color_encoding default_color_encoding;
+ unsigned int supported_color_encodings;
struct xarray possible_crtcs;
bool default_pipeline;

@@ -375,6 +379,66 @@ bool vkms_config_valid_plane_rotation(const struct vkms_config *config,
const struct vkms_config_plane *plane_cfg);
#endif

+/**
+ * vkms_config_plane_get_default_color_encoding() - Get the default color encoding for a plane
+ * @plane_cfg: Plane to get the default color encoding from
+ *
+ * Returns:
+ * The default color encoding for the plane
+ */
+static inline enum drm_color_encoding
+vkms_config_plane_get_default_color_encoding(const struct vkms_config_plane *plane_cfg)
+{
+ return plane_cfg->default_color_encoding;
+}
+
+/**
+ * vkms_config_plane_set_default_color_encoding() - Set the default color encoding for a plane
+ * @plane_cfg: Plane to set the default color encoding to
+ * @default_color_encoding: New default color encoding for the plane
+ */
+static inline void
+vkms_config_plane_set_default_color_encoding(struct vkms_config_plane *plane_cfg,
+ enum drm_color_encoding default_color_encoding)
+{
+ plane_cfg->default_color_encoding = default_color_encoding;
+}
+
+/**
+ * vkms_config_plane_get_supported_color_encodings() - Get the supported color encodings for a plane
+ * @plane_cfg: Plane to get the supported color encodings from
+ *
+ * Returns:
+ * The supported color encodings for the plane. Each set bit correspond to a value of enum
+ * drm_color_encoding: BIT(DRM_COLOR_YCBCR_BT601) | BIT(DRM_COLOR_YCBCR_BT709) means that
+ * DRM_COLOR_YCBCR_BT601 and DRM_COLOR_YCBCR_BT709 are supported.
+ */
+static inline unsigned int
+vkms_config_plane_get_supported_color_encodings(const struct vkms_config_plane *plane_cfg)
+{
+ return plane_cfg->supported_color_encodings;
+}
+
+/**
+ * vkms_config_plane_set_supported_color_encodings() - Set the supported color encodings for a plane
+ * @plane_cfg: Plane to set the supported color encodings to
+ * @supported_color_encodings: New supported color encodings for the plane. Each set bit corresponds
+ * to a value of enum drm_color_encoding:
+ * BIT(DRM_COLOR_YCBCR_BT601) | BIT(DRM_COLOR_YCBCR_BT709) means that
+ * DRM_COLOR_YCBCR_BT601 and DRM_COLOR_YCBCR_BT709 are supported.
+ */
+static inline void
+vkms_config_plane_set_supported_color_encodings(struct vkms_config_plane *plane_cfg,
+ unsigned int supported_color_encodings)
+{
+ plane_cfg->supported_color_encodings = supported_color_encodings;
+}
+
+#if IS_ENABLED(CONFIG_KUNIT)
+bool vkms_config_valid_plane_color_encoding(const struct vkms_config *config,
+ const struct vkms_config_plane *plane_cfg);
+#endif
+
/**
* vkms_config_plane_set_name() - Set the plane name
* @plane_cfg: Plane to set the name to
diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c
index 17d9c6f639b2..4b3bd2a90058 100644
--- a/drivers/gpu/drm/vkms/vkms_plane.c
+++ b/drivers/gpu/drm/vkms/vkms_plane.c
@@ -239,14 +239,13 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
vkms_config_plane_get_default_rotation(plane_cfg),
vkms_config_plane_get_supported_rotations(plane_cfg));

- drm_plane_create_color_properties(&plane->base,
- BIT(DRM_COLOR_YCBCR_BT601) |
- BIT(DRM_COLOR_YCBCR_BT709) |
- BIT(DRM_COLOR_YCBCR_BT2020),
- BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
- BIT(DRM_COLOR_YCBCR_FULL_RANGE),
- DRM_COLOR_YCBCR_BT601,
- DRM_COLOR_YCBCR_FULL_RANGE);
+ if (vkms_config_plane_get_supported_color_encodings(plane_cfg) != 0)
+ drm_plane_create_color_properties(&plane->base,
+ vkms_config_plane_get_supported_color_encodings(plane_cfg),
+ BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
+ BIT(DRM_COLOR_YCBCR_FULL_RANGE),
+ vkms_config_plane_get_default_color_encoding(plane_cfg),
+ DRM_COLOR_YCBCR_FULL_RANGE);

if (vkms_config_plane_get_default_pipeline(plane_cfg))
vkms_initialize_colorops(&plane->base);

--
2.54.0