[PATCH RESEND v2 21/32] drm/vkms: Introduce config for connector type

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

In order to emulate connector-specific behavior, add connector type
configuration.

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/vkms/tests/vkms_config_test.c | 5 +++++
drivers/gpu/drm/vkms/vkms_config.c | 3 +++
drivers/gpu/drm/vkms/vkms_config.h | 24 ++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_connector.c | 5 +++--
drivers/gpu/drm/vkms/vkms_connector.h | 3 ++-
drivers/gpu/drm/vkms/vkms_output.c | 2 +-
6 files changed, 38 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 518e68c17122..c8b885306eed 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_config_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
@@ -128,6 +128,7 @@ static void vkms_config_test_default_config(struct kunit *test)
struct vkms_config *config;
struct vkms_config_plane *plane_cfg;
struct vkms_config_crtc *crtc_cfg;
+ struct vkms_config_connector *connector_cfg;
int n_primaries = 0;
int n_cursors = 0;
int n_overlays = 0;
@@ -198,6 +199,10 @@ static void vkms_config_test_default_config(struct kunit *test)

/* Connectors */
KUNIT_EXPECT_EQ(test, vkms_config_get_num_connectors(config), 1);
+ 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_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 801019cf04c1..02e2f0249fb0 100644
--- a/drivers/gpu/drm/vkms/vkms_config.c
+++ b/drivers/gpu/drm/vkms/vkms_config.c
@@ -588,6 +588,8 @@ static int vkms_config_show(struct seq_file *m, void *data)
seq_puts(m, "connector:\n");
seq_printf(m, "\tstatus=%s\n",
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)));
}

return 0;
@@ -893,6 +895,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);
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 baed036a07cd..6a50ec7535af 100644
--- a/drivers/gpu/drm/vkms/vkms_config.h
+++ b/drivers/gpu/drm/vkms/vkms_config.h
@@ -128,6 +128,7 @@ struct vkms_config_encoder {
* struct vkms_config_connector
*
* @link: Link to the others connector in vkms_config
+ * @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
* @possible_encoders: Array of encoders that can be used with this connector
@@ -140,6 +141,7 @@ struct vkms_config_connector {
struct list_head link;
struct vkms_config *config;

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

@@ -317,6 +319,28 @@ vkms_config_plane_set_type(struct vkms_config_plane *plane_cfg,
}

/**
+ * vkms_config_connector_get_type() - Return the connector type
+ * @connector_cfg: Connector to get the type from
+ */
+static inline int
+vkms_config_connector_get_type(const struct vkms_config_connector *connector_cfg)
+{
+ return connector_cfg->type;
+}
+
+/**
+ * vkms_config_connector_set_type() - Set the connector type
+ * @connector_cfg: Connector to set the type to
+ * @type: New connector type
+ */
+static inline void
+vkms_config_connector_set_type(struct vkms_config_connector *connector_cfg,
+ int type)
+{
+ connector_cfg->type = type;
+}
+
+/*
* vkms_config_plane_get_default_rotation() - Get the default rotation for a plane
* @plane_cfg: Plane to get the default rotation from
*
diff --git a/drivers/gpu/drm/vkms/vkms_connector.c b/drivers/gpu/drm/vkms/vkms_connector.c
index b0a6b212d3f4..5a87dc2d4c63 100644
--- a/drivers/gpu/drm/vkms/vkms_connector.c
+++ b/drivers/gpu/drm/vkms/vkms_connector.c
@@ -68,7 +68,8 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
.best_encoder = vkms_conn_best_encoder,
};

-struct vkms_connector *vkms_connector_init(struct vkms_device *vkmsdev)
+struct vkms_connector *vkms_connector_init(struct vkms_device *vkmsdev,
+ struct vkms_config_connector *connector_cfg)
{
struct drm_device *dev = &vkmsdev->drm;
struct vkms_connector *connector;
@@ -79,7 +80,7 @@ struct vkms_connector *vkms_connector_init(struct vkms_device *vkmsdev)
return ERR_PTR(-ENOMEM);

ret = drmm_connector_init(dev, &connector->base, &vkms_connector_funcs,
- DRM_MODE_CONNECTOR_VIRTUAL, NULL);
+ vkms_config_connector_get_type(connector_cfg), NULL);
if (ret)
return ERR_PTR(ret);

diff --git a/drivers/gpu/drm/vkms/vkms_connector.h b/drivers/gpu/drm/vkms/vkms_connector.h
index ed312f4eff3a..a124c5403697 100644
--- a/drivers/gpu/drm/vkms/vkms_connector.h
+++ b/drivers/gpu/drm/vkms/vkms_connector.h
@@ -24,7 +24,8 @@ struct vkms_connector {
* Returns:
* The connector or an error on failure.
*/
-struct vkms_connector *vkms_connector_init(struct vkms_device *vkmsdev);
+struct vkms_connector *vkms_connector_init(struct vkms_device *vkmsdev,
+ struct vkms_config_connector *connector_cfg);

/**
* vkms_trigger_connector_hotplug() - Update the device's connectors status
diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
index 22208d02afa4..217f054d9598 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -96,7 +96,7 @@ int vkms_output_init(struct vkms_device *vkmsdev)
struct vkms_config_encoder *possible_encoder;
unsigned long idx = 0;

- connector_cfg->connector = vkms_connector_init(vkmsdev);
+ connector_cfg->connector = vkms_connector_init(vkmsdev, connector_cfg);
if (IS_ERR(connector_cfg->connector)) {
DRM_ERROR("Failed to init connector\n");
return PTR_ERR(connector_cfg->connector);

--
2.51.0