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 9BD7CF46449 for ; Mon, 16 Mar 2026 10:23:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 516FD10E25A; Mon, 16 Mar 2026 10:23:59 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="n7BGKLFw"; dkim-atps=neutral Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) by gabe.freedesktop.org (Postfix) with ESMTPS id C065410E258 for ; Mon, 16 Mar 2026 10:23:50 +0000 (UTC) Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id A88A64E426C0; Mon, 16 Mar 2026 10:23:49 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 68BFD5FC9A; Mon, 16 Mar 2026 10:23:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E58F810368615; Mon, 16 Mar 2026 11:23:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1773656628; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=STczcMVk0JCqbGgtFjZji1Rze5+NL+qkw6bbV45a03Y=; b=n7BGKLFw9ryXurgYage6LcyrBCFPl9XdavCZb3TEpJ6PY24wWy4X69G3cD55vzUJaZknZF 7cNbmRi+m2DbXLyeG7AKPcZ9GlGeAksJGRxSHvtXrROaey0OYYXAKmpP7+BTrqsdnXQ4t/ h45OOZ5IhHeugvQLxS0wDxLBuWh8HZaUkjWIz8KPnZj+1PCW1GD/BL95PqO+B7rQ+qdM43 2LBAKd3axybua5ahD0XafLPOnjRMsZgg5/kAES/mh1VGhQmNj9v8hZ2hH4WxV+V4AQqcIm WjZpW/coRcfKs7jl1oiDj/uaMktvSie2dwtIVZ3jZTTymIZxcrL05GZXntYAaQ== From: Louis Chauvet Date: Mon, 16 Mar 2026 11:24:12 +0100 Subject: [PATCH i-g-t v8 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: <20260316-unigraf-integration-v8-4-4489bf8572be@bootlin.com> References: <20260316-unigraf-integration-v8-0-4489bf8572be@bootlin.com> In-Reply-To: <20260316-unigraf-integration-v8-0-4489bf8572be@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.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4853; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=rf2J+XcjbZ5kIHDejR76RZXeKXK6Z9SZnxTwhy893qs=; b=owEBiQJ2/ZANAwAIASCtLsZbECziAcsmYgBpt9pOqOVRXJUxHqlR7gempQRCaPUFG8P29NBqR nhDtf1kUleJAk8EAAEIADkWIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCabfaThsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMSwyLDIACgkQIK0uxlsQLOIBMQ/9HoBI3Z6LwufV8rIjUyTL7kwPUwScMjh 4P1DihOSLcPKv7mRtPfEJrjkoJjj+vcYTetjpXI6wa53lOUREUd0N3nqU2o4+HPzfB5jOKt7YQ2 tY973h+NIFgHxomJciPPTStnCARE213JT/0chciObcqwoYqLUR47YYNro1YiFN7nYETSAQfIlkE bq7CES/Xa6DBWVl9n6TwgvtBzqds42JWEM07ok55pcoMI/f+BULdnqV8n3ILbDdEZbYOrBT/8JS PKaC33ypp2dIXcP2r8kJlTHIg0uUDZ8FdR1a1wMdza7GB8Ff8vtr4PNo65Pvk6/1Qz4GCVau6VI GKm7zaZNDF75Rbm2yRYYmVUX42vvK7+s06LsS2AsVYwpaxWQAZUe0Cxgzu6E/+CCfVc0+1iHrrF yFOAj18EAd+gxCZQfe8Hj+bLcz43679xhLmQgmr8YXFiFH1yBTWuu7SSjvJHpO0ZiWpQAD2cdk6 5jkFppLN8cbWEdnjIe5SaWlFIe07CK82puDGyJl/Pxc9ty7krhWuYjYkF4mOKask4N3WBBcws9J kHhWCXWP3VyhG++iYByxuk5YtCqy768X5XFJpIpLVeK/XGehJZRMo1d3HRRWO7ggrEMxzKOZMar Z9kzgg2ZCr9kkUztrkGuyMNdK0S90aHcE6w0H3LzQ5yR4OAbnLCo= X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 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 72a38334f921..f0f27ccda9d8 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -95,6 +95,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); @@ -8214,3 +8218,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 4efd40a3ad08..0095d9610e42 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -1304,5 +1304,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.52.0