[PATCH i-g-t v2 27/39] lib/chamelium/v3: Implement helper function to retrieve connector from port mapping

Louis Chauvet louis.chauvet at bootlin.com
Tue Jul 9 15:34:43 UTC 2024


This commit introduces a helper function that utilizes igt_kms helpers to
easily obtain the connector object from a given port mapping in Chamelium,
simplifying the process for users.

Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
---
 lib/chamelium/v3/igt_chamelium.c | 43 ++++++++++++++++++++++++++++++++++++++++
 lib/chamelium/v3/igt_chamelium.h |  7 +++++++
 2 files changed, 50 insertions(+)

diff --git a/lib/chamelium/v3/igt_chamelium.c b/lib/chamelium/v3/igt_chamelium.c
index fc9520466de5..51b3a610e358 100644
--- a/lib/chamelium/v3/igt_chamelium.c
+++ b/lib/chamelium/v3/igt_chamelium.c
@@ -5,6 +5,7 @@
 
 #include "igt_chamelium.h"
 #include "igt_core.h"
+#include "igt_kms.h"
 #include "igt_rc.h"
 
 #define CHAMELIUM_CONFIG_SECTION "Chameliumv3"
@@ -392,6 +393,48 @@ struct igt_list_head *chamelium_v3_get_port_mapping(struct igt_chamelium_v3 *cha
 	return &chamelium->port_mapping;
 }
 
+/**
+ * chamelium_v3_port_mapping_get_connector - Get a drm connector from a port mapping
+ *
+ * @port_mapping: Port mapping to retrieve the connector from
+ * @drm_fd: drm file descriptor to use when requesting the connector
+ *
+ * This function only works with non-MST port mapping.
+ *
+ * Returns a drm connector that must be freed with drmModeConnectorFree when not needed anymore.
+ * A null pointer means that the connector can't be found.
+ */
+drmModeConnectorPtr
+chamelium_v3_port_mapping_get_connector(const struct chamelium_v3_port_mapping *port_mapping,
+					int drm_fd)
+{
+	if (port_mapping->mst_path) {
+		igt_warn("Directly getting a connector from its MST path is not supported");
+		return NULL;
+	} else {
+		return igt_get_connector_from_name(drm_fd, port_mapping->connector_name);
+	}
+}
+
+/**
+ * chamelium_v3_port_mapping_get_connector_id - Get a drm connector id from a port mapping
+ *
+ * @port_mapping: Port mapping to retrieve the connector id from
+ * @drm_fd: drm file descriptor to use when requesting the connector id
+ *
+ * Returns a drm connector id that represent the port mapping given in parameter. A connector id of
+ * zero means that the connector is not found.
+ */
+uint32_t
+chamelium_v3_port_mapping_get_connector_id(const struct chamelium_v3_port_mapping *port_mapping,
+					   int drm_fd)
+{
+	if (port_mapping->mst_path)
+		return igt_get_connector_id_from_mst_path(drm_fd, port_mapping->mst_path);
+	else
+		return igt_get_connector_id_from_name(drm_fd, port_mapping->connector_name);
+}
+
 /**
  * __chamelium_rpc - Call a remote function on the chamelium
  *
diff --git a/lib/chamelium/v3/igt_chamelium.h b/lib/chamelium/v3/igt_chamelium.h
index 5e035bdd10bf..90d2a7473894 100644
--- a/lib/chamelium/v3/igt_chamelium.h
+++ b/lib/chamelium/v3/igt_chamelium.h
@@ -49,6 +49,13 @@ struct igt_list_head *chamelium_v3_get_port_mapping(struct igt_chamelium_v3 *cha
 struct chamelium_v3_port_mapping *
 chamelium_v3_get_port_mapping_for_chamelium_port_id(struct igt_chamelium_v3 *chamelium,
 						    chamelium_v3_port_id port_id);
+uint32_t
+chamelium_v3_port_mapping_get_connector_id(const struct chamelium_v3_port_mapping *port_mapping,
+					   int drm_fd);
+drmModeConnectorPtr
+chamelium_v3_port_mapping_get_connector(const struct chamelium_v3_port_mapping *port_mapping,
+					int drm_fd);
+
 void chamelium_v3_uninit(struct igt_chamelium_v3 *chamelium);
 
 void chamelium_v3_reset(struct igt_chamelium_v3 *chamelium);

-- 
2.44.2



More information about the igt-dev mailing list