[PATCH RESEND v2 14/32] drm/vkms: Introduce config for plane color range

Louis Chauvet
2025-10-29T14:37:17Z

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

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/vkms/tests/vkms_config_test.c | 44 +++++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_config.c | 39 ++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_config.h | 35 +++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_plane.c | 8 ++---
4 files changed, 122 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/vkms/tests/vkms_config_test.c b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
index e9bc051188f9..d962fec8d3b3 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_config_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0+

+#include <drm/drm_color_mgmt.h>
#include <drm/drm_mode.h>
#include <kunit/test.h>

@@ -549,6 +550,7 @@ static void vkms_config_test_valid_plane_color_encoding(struct kunit *test)
KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));

/* Valid, no supported or color encoding */
+ vkms_config_plane_set_supported_color_ranges(plane_cfg, 0);
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));
@@ -563,6 +565,47 @@ static void vkms_config_test_valid_plane_color_encoding(struct kunit *test)
vkms_config_destroy(config);
}

+static void vkms_config_test_valid_plane_color_range(struct kunit *test)
+{
+ struct vkms_config *config;
+ struct vkms_config_plane *plane_cfg;
+
+ config = vkms_config_default_create(false, false, false);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config);
+
+ plane_cfg = get_first_plane(config);
+
+ /* Valid, all color range supported */
+ vkms_config_plane_set_supported_color_ranges(plane_cfg,
+ BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
+ BIT(DRM_COLOR_YCBCR_FULL_RANGE));
+ vkms_config_plane_set_default_color_range(plane_cfg, DRM_COLOR_YCBCR_FULL_RANGE);
+ KUNIT_EXPECT_TRUE(test, vkms_config_valid_plane_color_range(config, plane_cfg));
+ KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config));
+
+ /* Invalid, default color range is not supported */
+ vkms_config_plane_set_supported_color_ranges(plane_cfg,
+ BIT(DRM_COLOR_YCBCR_FULL_RANGE));
+ vkms_config_plane_set_default_color_range(plane_cfg, DRM_COLOR_YCBCR_LIMITED_RANGE);
+ KUNIT_EXPECT_FALSE(test, vkms_config_valid_plane_color_range(config, plane_cfg));
+ KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));
+
+ /* Valid, no supported or color range */
+ vkms_config_plane_set_supported_color_encodings(plane_cfg, 0);
+ vkms_config_plane_set_supported_color_ranges(plane_cfg, 0);
+ vkms_config_plane_set_default_color_range(plane_cfg, 0);
+ KUNIT_EXPECT_TRUE(test, vkms_config_valid_plane_color_range(config, plane_cfg));
+ KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config));
+
+ /* Valid, if no supported color range, default is ignored */
+ vkms_config_plane_set_supported_color_ranges(plane_cfg, 0);
+ vkms_config_plane_set_default_color_range(plane_cfg, DRM_COLOR_YCBCR_LIMITED_RANGE);
+ KUNIT_EXPECT_TRUE(test, vkms_config_valid_plane_color_range(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;
@@ -1087,6 +1130,7 @@ static struct kunit_case vkms_config_test_cases[] = {
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_color_range),
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 6a3d52c1141d..823039fb4145 100644
--- a/drivers/gpu/drm/vkms/vkms_config.c
+++ b/drivers/gpu/drm/vkms/vkms_config.c
@@ -194,6 +194,25 @@ bool vkms_config_valid_plane_color_encoding(const struct vkms_config *config,
}
EXPORT_SYMBOL_IF_KUNIT(vkms_config_valid_plane_color_encoding);

+VISIBLE_IF_KUNIT
+bool vkms_config_valid_plane_color_range(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_ranges(plane_cfg)) {
+ if ((BIT(vkms_config_plane_get_default_color_range(plane_cfg)) &
+ vkms_config_plane_get_supported_color_ranges(plane_cfg)) !=
+ BIT(vkms_config_plane_get_default_color_range(plane_cfg))) {
+ drm_info(dev, "Configured default color range is not supported by the plane\n");
+ return false;
+ }
+ }
+
+ return true;
+}
+EXPORT_SYMBOL_IF_KUNIT(vkms_config_valid_plane_color_range);
+
static bool valid_planes_for_crtc(const struct vkms_config *config,
struct vkms_config_crtc *crtc_cfg)
{
@@ -350,6 +369,7 @@ static bool valid_connector_possible_encoders(const struct vkms_config *config)

bool vkms_config_is_valid(const struct vkms_config *config)
{
+ struct drm_device *dev = config->dev ? &config->dev->drm : NULL;
struct vkms_config_crtc *crtc_cfg;
struct vkms_config_plane *plane_cfg;

@@ -359,6 +379,16 @@ bool vkms_config_is_valid(const struct vkms_config *config)

if (!vkms_config_valid_plane_color_encoding(config, plane_cfg))
return false;
+
+ if (!vkms_config_valid_plane_color_range(config, plane_cfg))
+ return false;
+
+ if ((vkms_config_plane_get_supported_color_encodings(plane_cfg) == 0) !=
+ (vkms_config_plane_get_supported_color_ranges(plane_cfg) == 0)) {
+ drm_info(dev,
+ "Both supported color encoding and color range must be set, or none\n");
+ return false;
+ }
}

if (!valid_plane_number(config))
@@ -441,6 +471,12 @@ static int vkms_config_show(struct seq_file *m, void *data)
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)));
+ seq_puts(m, "\tsupported color range=");
+ show_bitfield(m, vkms_config_plane_get_supported_color_ranges(plane_cfg),
+ drm_get_color_range_name);
+ seq_puts(m, "\n");
+ seq_printf(m, "\tdefault color range=%s\n",
+ drm_get_color_range_name(vkms_config_plane_get_default_color_range(plane_cfg)));
}

vkms_config_for_each_crtc(vkmsdev->config, crtc_cfg) {
@@ -489,6 +525,9 @@ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *config)
BIT(DRM_COLOR_YCBCR_BT709) |
BIT(DRM_COLOR_YCBCR_BT2020));
vkms_config_plane_set_default_color_encoding(plane_cfg, DRM_COLOR_YCBCR_BT601);
+ vkms_config_plane_set_supported_color_ranges(plane_cfg, BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
+ BIT(DRM_COLOR_YCBCR_FULL_RANGE));
+ vkms_config_plane_set_default_color_range(plane_cfg, DRM_COLOR_YCBCR_FULL_RANGE);

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 d740c9478256..d8648bf844d4 100644
--- a/drivers/gpu/drm/vkms/vkms_config.h
+++ b/drivers/gpu/drm/vkms/vkms_config.h
@@ -47,6 +47,8 @@ struct vkms_config {
* must be managed by other means.
* @default_color_encoding: Default color encoding that should be used by this plane
* @supported_color_encodings: Color encoding that this plane will support
+ * @default_color_range: Default color range that should be used by this plane
+ * @supported_color_ranges: Color range that this plane will support
*/
struct vkms_config_plane {
struct list_head link;
@@ -58,6 +60,8 @@ struct vkms_config_plane {
unsigned int supported_rotations;
enum drm_color_encoding default_color_encoding;
unsigned int supported_color_encodings;
+ enum drm_color_range default_color_range;
+ unsigned int supported_color_ranges;
struct xarray possible_crtcs;

/* Internal usage */
@@ -413,6 +417,37 @@ bool vkms_config_valid_plane_color_encoding(const struct vkms_config *config,
const struct vkms_config_plane *plane_cfg);
#endif

+static inline enum drm_color_range
+vkms_config_plane_get_default_color_range(const struct vkms_config_plane *plane_cfg)
+{
+ return plane_cfg->default_color_range;
+}
+
+static inline void
+vkms_config_plane_set_default_color_range(struct vkms_config_plane *plane_cfg,
+ enum drm_color_range default_color_range)
+{
+ plane_cfg->default_color_range = default_color_range;
+}
+
+static inline unsigned int
+vkms_config_plane_get_supported_color_ranges(const struct vkms_config_plane *plane_cfg)
+{
+ return plane_cfg->supported_color_ranges;
+}
+
+static inline void
+vkms_config_plane_set_supported_color_ranges(struct vkms_config_plane *plane_cfg,
+ unsigned int supported_color_ranges)
+{
+ plane_cfg->supported_color_ranges = supported_color_ranges;
+}
+
+#if IS_ENABLED(CONFIG_KUNIT)
+bool vkms_config_valid_plane_color_range(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 9550831be51a..5dbc7c67de1d 100644
--- a/drivers/gpu/drm/vkms/vkms_plane.c
+++ b/drivers/gpu/drm/vkms/vkms_plane.c
@@ -238,13 +238,13 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
vkms_config_plane_get_default_rotation(config),
vkms_config_plane_get_supported_rotations(config));

- if (vkms_config_plane_get_supported_color_encodings(config) != 0)
+ if (vkms_config_plane_get_supported_color_encodings(config) != 0 &&
+ vkms_config_plane_get_supported_color_ranges(config) != 0)
drm_plane_create_color_properties(&plane->base,
vkms_config_plane_get_supported_color_encodings(config),
- BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
- BIT(DRM_COLOR_YCBCR_FULL_RANGE),
+ vkms_config_plane_get_supported_color_ranges(config),
vkms_config_plane_get_default_color_encoding(config),
- DRM_COLOR_YCBCR_FULL_RANGE);
+ vkms_config_plane_get_default_color_range(config));

return plane;
}

--
2.51.0