[PATCH v4 31/37] drm/vkms: Introduce config for connector EDID

Louis Chauvet
2026-04-22T16:50:17Z

Allows configuration of EDID for each connector.

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 | 2 +
drivers/gpu/drm/vkms/vkms_config.c | 6 +++
drivers/gpu/drm/vkms/vkms_config.h | 75 +++++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_connector.c | 50 ++++++++++++++++--
4 files changed, 129 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 a31fd230c1d4..2b49745ee026 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_config_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
@@ -218,6 +218,8 @@ static void vkms_config_test_default_config(struct kunit *test)
KUNIT_EXPECT_EQ(test,
vkms_config_connector_get_supported_colorspaces(connector_cfg),
0);
+ KUNIT_EXPECT_EQ(test, vkms_config_connector_get_edid_enabled(connector_cfg),
+ false);
}

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 b0511e6fc64d..eee6401a3e4f 100644
--- a/drivers/gpu/drm/vkms/vkms_config.c
+++ b/drivers/gpu/drm/vkms/vkms_config.c
@@ -538,6 +538,7 @@ static int vkms_config_show(struct seq_file *m, void *data)
struct drm_device *dev = entry->dev;
struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
const char *dev_name;
+ int edid_len;
struct vkms_config_plane *plane_cfg;
struct vkms_config_crtc *crtc_cfg;
struct vkms_config_encoder *encoder_cfg;
@@ -608,6 +609,11 @@ static int vkms_config_show(struct seq_file *m, void *data)
show_bitfield(m, vkms_config_connector_get_supported_colorspaces(connector_cfg),
drm_get_colorspace_name);
seq_puts(m, "\n");
+ vkms_config_connector_get_edid(connector_cfg, &edid_len);
+ seq_printf(m, "\tEDID=%s (len=%d)\n",
+ str_enabled_disabled(vkms_config_connector_get_edid_enabled(connector_cfg)),
+ edid_len
+ );
}

return 0;
diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
index e62bb6603a69..3489c682b4af 100644
--- a/drivers/gpu/drm/vkms/vkms_config.h
+++ b/drivers/gpu/drm/vkms/vkms_config.h
@@ -136,6 +136,9 @@ struct vkms_config_encoder {
* are the sames as ones accepted by
* drm_mode_create_hdmi_colorspace_property() and
* drm_mode_create_dp_colorspace_property()
+ * @edid_enabled: If true, create the EDID property
+ * @edid: Stores the current EDID. The value will be ignored if @edid_enabled is false
+ * @edid_len: Current EDID length. The value will be ignored if @edid_enabled is false
* @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
@@ -149,6 +152,9 @@ struct vkms_config_connector {
int type;
enum drm_connector_status status;
u32 supported_colorspaces;
+ bool edid_enabled;
+ u8 *edid;
+ unsigned int edid_len;
struct xarray possible_encoders;

/* Internal usage */
@@ -273,6 +279,75 @@ vkms_config_connector_get_supported_colorspaces(const struct vkms_config_connect
return connector_cfg->supported_colorspaces;
}

+/**
+ * vkms_config_connector_get_edid_enabled() - Check if EDID is enabled for a connector
+ * @connector_cfg: Connector configuration to check
+ *
+ * Returns:
+ * True if EDID is enabled for this connector, false otherwise.
+ */
+static inline bool
+vkms_config_connector_get_edid_enabled(const struct vkms_config_connector *connector_cfg)
+{
+ return connector_cfg->edid_enabled;
+}
+
+/**
+ * vkms_config_connector_set_edid_enabled() - Enable or disable EDID for a connector
+ * @connector_cfg: Connector configuration to modify
+ * @enabled: Whether to enable EDID for this connector
+ */
+static inline void
+vkms_config_connector_set_edid_enabled(struct vkms_config_connector *connector_cfg,
+ bool enabled)
+{
+ connector_cfg->edid_enabled = enabled;
+}
+
+/**
+ * vkms_config_connector_get_edid() - Get the EDID data for a connector
+ * @connector_cfg: Connector configuration to get the EDID from
+ * @len: Pointer to store the length of the EDID data
+ *
+ * Returns:
+ * Pointer to the EDID data buffer, or NULL if no EDID is set.
+ * The length of the EDID data is stored in @len.
+ */
+static inline const u8 *
+vkms_config_connector_get_edid(const struct vkms_config_connector *connector_cfg, int *len)
+{
+ *len = connector_cfg->edid_len;
+ return connector_cfg->edid;
+}
+
+/**
+ * vkms_config_connector_set_edid() - Set the EDID data for a connector
+ * @connector_cfg: Connector configuration to modify
+ * @edid: Pointer to the EDID data buffer
+ * @len: Length of the EDID data
+ *
+ * If @len is 0, the EDID data will be cleared and @edid ignored. If
+ * memory allocation fails, the existing EDID data will be preserved.
+ */
+static inline void
+vkms_config_connector_set_edid(struct vkms_config_connector *connector_cfg,
+ const u8 *edid, unsigned int len)
+{
+ if (len) {
+ void *edid_tmp = krealloc(connector_cfg->edid, len, GFP_KERNEL);
+
+ if (edid_tmp) {
+ connector_cfg->edid = edid_tmp;
+ memcpy(connector_cfg->edid, edid, len);
+ connector_cfg->edid_len = len;
+ }
+ } else {
+ kfree(connector_cfg->edid);
+ connector_cfg->edid = NULL;
+ connector_cfg->edid_len = len;
+ }
+}
+
/**
* 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 a1f08167def1..fe42ab2ba7b1 100644
--- a/drivers/gpu/drm/vkms/vkms_connector.c
+++ b/drivers/gpu/drm/vkms/vkms_connector.c
@@ -42,13 +42,55 @@ static const struct drm_connector_funcs vkms_connector_funcs = {
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
};

+static int vkms_connector_read_block(void *context, u8 *buf, unsigned int block, size_t len)
+{
+ struct vkms_config_connector *config = context;
+ unsigned int edid_len;
+ const u8 *edid = vkms_config_connector_get_edid(config, &edid_len);
+
+ if (block * len + len > edid_len)
+ return 1;
+ memcpy(buf, &edid[block * len], len);
+ return 0;
+}
+
static int vkms_conn_get_modes(struct drm_connector *connector)
{
- int count;
+ struct vkms_connector *vkms_connector = drm_connector_to_vkms_connector(connector);
+ const struct drm_edid *drm_edid = NULL;
+ int count = 0;
+ struct vkms_config_connector *context = NULL;
+ struct drm_device *dev = connector->dev;
+ struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
+ struct vkms_config_connector *connector_cfg;

- /* Use the default modes list from DRM */
- count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
- drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
+ vkms_config_for_each_connector(vkmsdev->config, connector_cfg) {
+ if (connector_cfg->connector == vkms_connector) {
+ context = connector_cfg;
+ break;
+ }
+ }
+ if (context) {
+ if (vkms_config_connector_get_edid_enabled(context)) {
+ drm_edid = drm_edid_read_custom(connector,
+ vkms_connector_read_block, context);
+
+ /*
+ * Unconditionally update the connector. If the EDID was read
+ * successfully, fill in the connector information derived from the
+ * EDID. Otherwise, if the EDID is NULL, clear the connector
+ * information.
+ */
+ drm_edid_connector_update(connector, drm_edid);
+
+ count = drm_edid_connector_add_modes(connector);
+
+ drm_edid_free(drm_edid);
+ } else {
+ count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
+ drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
+ }
+ }

return count;
}

--
2.54.0