[PATCH v3 25/33] drm/vkms: Introduce config for connector supported colorspace

Louis Chauvet
2025-12-22T10:12:35Z

To emulate some HDR features of displays, it is required to expose some
properties on HDMI, eDP and DP connectors.

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 | 3 +++
drivers/gpu/drm/vkms/vkms_config.c | 5 +++++
drivers/gpu/drm/vkms/vkms_config.h | 30 +++++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_connector.c | 15 ++++++++++++++
4 files changed, 53 insertions(+)

diff --git a/drivers/gpu/drm/vkms/tests/vkms_config_test.c b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
index 1900cc79db2b..a31fd230c1d4 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_config_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
@@ -215,6 +215,9 @@ static void vkms_config_test_default_config(struct kunit *test)
vkms_config_for_each_connector(config, connector_cfg) {
KUNIT_EXPECT_EQ(test, vkms_config_connector_get_type(connector_cfg),
DRM_MODE_CONNECTOR_VIRTUAL);
+ KUNIT_EXPECT_EQ(test,
+ vkms_config_connector_get_supported_colorspaces(connector_cfg),
+ 0);
}

KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config));
diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c
index 59ce55efb167..de661c85c11f 100644
--- a/drivers/gpu/drm/vkms/vkms_config.c
+++ b/drivers/gpu/drm/vkms/vkms_config.c
@@ -591,6 +591,10 @@ static int vkms_config_show(struct seq_file *m, void *data)
drm_get_connector_status_name(vkms_config_connector_get_status(connector_cfg)));
seq_printf(m, "\ttype=%s\n",
drm_get_connector_type_name(vkms_config_connector_get_type(connector_cfg)));
+ seq_puts(m, "\tsupported colorspaces=");
+ show_bitfield(m, vkms_config_connector_get_supported_colorspaces(connector_cfg),
+ drm_get_colorspace_name);
+ seq_puts(m, "\n");
}

return 0;
@@ -908,6 +912,7 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *c
connector_cfg->config = config;
connector_cfg->status = connector_status_connected;
vkms_config_connector_set_type(connector_cfg, DRM_MODE_CONNECTOR_VIRTUAL);
+ vkms_config_connector_set_supported_colorspaces(connector_cfg, 0);
xa_init_flags(&connector_cfg->possible_encoders, XA_FLAGS_ALLOC);

list_add_tail(&connector_cfg->link, &config->connectors);
diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
index 4a4058b407e7..c9d777589cb6 100644
--- a/drivers/gpu/drm/vkms/vkms_config.h
+++ b/drivers/gpu/drm/vkms/vkms_config.h
@@ -132,6 +132,10 @@ struct vkms_config_encoder {
* @type: Store the type of connector using DRM_MODE_CONNECTOR_* values
* @config: The vkms_config this connector belongs to
* @status: Status (connected, disconnected...) of the connector
+ * @supported_colorspaces: Bitmask of all the supported colorspaces. Values
+ * are the sames as ones accepted by
+ * drm_mode_create_hdmi_colorspace_property() and
+ * drm_mode_create_dp_colorspace_property()
* @possible_encoders: Array of encoders that can be used with this connector
* @connector: Internal usage. This pointer should never be considered as valid.
* It can be used to store a temporary reference to a VKMS connector
@@ -144,6 +148,7 @@ struct vkms_config_connector {

int type;
enum drm_connector_status status;
+ u32 supported_colorspaces;
struct xarray possible_encoders;

/* Internal usage */
@@ -243,6 +248,31 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,
*/
void vkms_config_destroy(struct vkms_config *config);

+/**
+ * vkms_config_connector_set_supported_colorspaces() - Set the supported colorspaces for a connector
+ * @connector_cfg: Connector configuration to modify
+ * @supported_colorspaces: Bitmask of supported colorspaces (DRM_MODE_COLORIMETRY_*)
+ */
+static inline void
+vkms_config_connector_set_supported_colorspaces(struct vkms_config_connector *connector_cfg,
+ u32 supported_colorspaces)
+{
+ connector_cfg->supported_colorspaces = supported_colorspaces;
+}
+
+/**
+ * vkms_config_connector_get_supported_colorspaces() - Get the supported colorspaces for a connector
+ * @connector_cfg: Connector configuration to query
+ *
+ * Returns:
+ * Bitmask of supported colorspaces (DRM_MODE_COLORIMETRY_*)
+ */
+static inline u32
+vkms_config_connector_get_supported_colorspaces(const struct vkms_config_connector *connector_cfg)
+{
+ return connector_cfg->supported_colorspaces;
+}
+
/**
* vkms_config_get_device_name() - Return the name of the device
* @config: Configuration to get the device name from
diff --git a/drivers/gpu/drm/vkms/vkms_connector.c b/drivers/gpu/drm/vkms/vkms_connector.c
index 5a87dc2d4c63..cc59d13c2d22 100644
--- a/drivers/gpu/drm/vkms/vkms_connector.c
+++ b/drivers/gpu/drm/vkms/vkms_connector.c
@@ -84,6 +84,21 @@ struct vkms_connector *vkms_connector_init(struct vkms_device *vkmsdev,
if (ret)
return ERR_PTR(ret);

+ if (vkms_config_connector_get_supported_colorspaces(connector_cfg)) {
+ if (connector_cfg->type == DRM_MODE_CONNECTOR_HDMIA) {
+ drm_mode_create_hdmi_colorspace_property(&connector->base,
+ vkms_config_connector_get_supported_colorspaces(connector_cfg));
+ drm_connector_attach_hdr_output_metadata_property(&connector->base);
+ drm_connector_attach_colorspace_property(&connector->base);
+ } else if (connector_cfg->type == DRM_MODE_CONNECTOR_DisplayPort ||
+ connector_cfg->type == DRM_MODE_CONNECTOR_eDP) {
+ drm_mode_create_dp_colorspace_property(&connector->base,
+ vkms_config_connector_get_supported_colorspaces(connector_cfg));
+ drm_connector_attach_hdr_output_metadata_property(&connector->base);
+ drm_connector_attach_colorspace_property(&connector->base);
+ }
+ }
+
drm_connector_helper_add(&connector->base, &vkms_conn_helper_funcs);

return connector;

--
2.51.2