Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2E2E3FED3F0 for ; Fri, 24 Apr 2026 16:58:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D0A048961D; Fri, 24 Apr 2026 16:58:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="Y0WVFOW2"; dkim-atps=neutral Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) by gabe.freedesktop.org (Postfix) with ESMTPS id 14566890BE for ; Fri, 24 Apr 2026 16:54:33 +0000 (UTC) Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 58B7BC5EF2E; Fri, 24 Apr 2026 16:55:13 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 84F1D604EB; Fri, 24 Apr 2026 16:54:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 4E6D010720A1A; Fri, 24 Apr 2026 18:54:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1777049671; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=OQtst3Fcj9X2pDrH4vaypL89E1RZw45WgTOmkeCf3U8=; b=Y0WVFOW2DV+riEzMqdNl2uNbg02ZJZtYzP7rAMPGpOJspkmE8j3YecIH98HxY6lK/tnUoD faKGbCEAtn1EPEqXtwipmJolo0zAMFhdEm7iys73hXa3Hxp0jrHVLvqkUQxJl695mqg1KL hC/teaMtZvVQpo6f6Hiyugo/ussyXXGKRBjRdpA8rifVUB6mCVq4m8P6mJINzZAbbH+xQA hIkATkfJC0ysItnPJpteq5e+DLI1ZC35JxXvvmuOxuIrVrZ9bohrBH8BBtrBNdKarIC/YR 7MRrbb4zaCRgH2pqYzN5K5u/Yi07C7MBNqO3ttCSIp32KcJSCbK7POTY0Y6IJA== From: Louis Chauvet Date: Fri, 24 Apr 2026 18:52:39 +0200 Subject: [PATCH i-g-t v11 04/49] lib/igt_kms: Add helper to obtain a connector by its name or MST path MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260424-unigraf-integration-v11-4-0c5f5346ae60@bootlin.com> References: <20260424-unigraf-integration-v11-0-0c5f5346ae60@bootlin.com> In-Reply-To: <20260424-unigraf-integration-v11-0-0c5f5346ae60@bootlin.com> To: igt-dev@lists.freedesktop.org Cc: thomas.petazzoni@bootlin.com, luca.ceresoli@bootlin.com, kory.maincent@bootlin.com, markyacoub@google.com, khaled.almahallawy@intel.com, Louis Chauvet X-Mailer: b4 0.16-dev X-Last-TLS-Session-Version: TLSv1.3 X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" Introduce the functions igt_get_connector_from_name() and igt_get_connector_id_from_mst_path(). These functions serve to retrieve the connector object using a connector name and a connector ID from its MST path, respectively. Given that the connector id may not be consistent, especially with MST connectors, these functions are essential to recognize each connector even after system reboots and plug/unplug events. The function igt_get_connector_id_from_name() is a convenient wrapper for igt_get_connector_from_name() to streamline its usage when the caller only requires the connector id. Signed-off-by: Louis Chauvet Reviewed-by: Luca Ceresoli Reviewed-by: Kory Maincent --- lib/igt_kms.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_kms.h | 3 ++ 2 files changed, 111 insertions(+) diff --git a/lib/igt_kms.c b/lib/igt_kms.c index dd733c3bdac5..0edc419dafc2 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -97,6 +97,10 @@ #define MAX_EDID 2 #define DISPLAY_TILE_BLOCK 0x12 #define MAX_NUM_COLOROPS 256 +/** + * IGT_KMS_CONNECTOR_NAME_SIZE - Size used when a connector name is needed + */ +#define IGT_KMS_CONNECTOR_NAME_SIZE 50 typedef bool (*igt_connector_attr_set)(int dir, const char *attr, const char *value); @@ -8310,3 +8314,107 @@ int igt_get_connected_connectors(int drm_fd, uint32_t **connector_ids) return connected_count; } + +/** + * igt_get_connector_from_name: + * @drm_fd: DRM file descriptor + * @port_name: Port name to search + * + * Returns: The connector if found, NULL otherwise. The pointer must + * be freed with drmModeFreeConnector() + */ +drmModeConnectorPtr igt_get_connector_from_name(int drm_fd, const char *port_name) +{ + double timeout = igt_default_display_detect_timeout(); + drmModeResPtr res = drmModeGetResources(drm_fd); + int i; + + if (!res) + return NULL; + + for (i = 0; i < res->count_connectors; i++) { + char name[IGT_KMS_CONNECTOR_NAME_SIZE]; + int len; + + drmModeConnectorPtr connector = igt_wait_for_connector(drm_fd, res->connectors[i], + timeout); + + if (connector) { + /* We have to generate the connector name on our own */ + len = snprintf(name, sizeof(name), "%s-%u", + kmstest_connector_type_str(connector->connector_type), + connector->connector_type_id); + name[len] = 0; + + if (strcmp(port_name, name) == 0) { + drmModeFreeResources(res); + + return connector; + } + + drmModeFreeConnector(connector); + } + } + + drmModeFreeResources(res); + + return NULL; +} + +/** + * igt_get_connector_id_from_name: + * @drm_fd: DRM file descriptor + * @port_name: Port name to find in the connector + * + * Returns: The connector id if the port is found, 0 if the port is not found + */ +uint32_t igt_get_connector_id_from_name(int drm_fd, const char *port_name) +{ + drmModeConnectorPtr connector = igt_get_connector_from_name(drm_fd, port_name); + + if (connector) { + uint32_t connector_id = connector->connector_id; + + drmModeFreeConnector(connector); + + return connector_id; + } + + return 0; +} + +/** + * igt_get_connector_id_from_mst_path: + * @drm_fd: DRM file descriptor + * @mst_path: MST path to find in the connector + * + * Returns: 0 when no connector is found with the correct mst path + */ +uint32_t igt_get_connector_id_from_mst_path(int drm_fd, const void *mst_path) +{ + drmModeResPtr res = drmModeGetResources(drm_fd); + int i; + + if (!res) + return 0; + + for (i = 0; i < res->count_connectors; i++) { + uint32_t connector_id = res->connectors[i]; + + drmModePropertyBlobPtr path_blob = kmstest_get_path_blob(drm_fd, connector_id); + + if (path_blob) { + if (memcmp(path_blob->data, mst_path, path_blob->length) == 0) { + drmModeFreePropertyBlob(path_blob); + drmModeFreeResources(res); + return connector_id; + } + + drmModeFreePropertyBlob(path_blob); + } + } + + drmModeFreeResources(res); + + return 0; +} diff --git a/lib/igt_kms.h b/lib/igt_kms.h index 75398a0f6369..1346aea5a6d5 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -1292,5 +1292,8 @@ igt_colorop_t *igt_find_colorop(igt_display_t *display, uint32_t id); bool igt_wait_for_connector_status(int drm_fd, unsigned int connector_id, double timeout, int drm_mode); int igt_get_connected_connectors(int drm_fd, uint32_t **connector_ids); +drmModeConnectorPtr igt_get_connector_from_name(int drm_fd, const char *port_name); +uint32_t igt_get_connector_id_from_name(int drm_fd, const char *port_name); +uint32_t igt_get_connector_id_from_mst_path(int drm_fd, const void *mst_path); #endif /* __IGT_KMS_H__ */ -- 2.54.0