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 DBE8ED62613 for ; Thu, 22 Jan 2026 11:05:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92C0A10E97A; Thu, 22 Jan 2026 11:05:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="AN1e47RC"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by gabe.freedesktop.org (Postfix) with ESMTPS id 706F110E02A for ; Thu, 22 Jan 2026 11:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769079927; x=1800615927; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d/1l3j7LuCrc+IemtUbb1a7I7hRdXz+mQU/coFbEM64=; b=AN1e47RCshaG1DODHQiAokKz/0DRltfccQji9cVoox2pAcK3YAmX9TCU kJDgbLcImSNey52k8wyS/8M14x2JSO6W4mkZDSV/EseNfvRVtMrnTz/+j S1KTVr+jSKdZmqyfltzsBRmKOq5ivsprZGazl6ZQQ1oCe9NOoDTcSoZjc +c4KECPL6U/upAIbiuqznocSx5nt9+NzfZITHKamj1FqoKn7SV2LaKPwC FpgK2ceYrfPBM7oGCdj5nmxuZSEUowIS9PGqugLks3MxJYGRkoKCQtdrb N04LBeYFyJ9300tIsDTQoBojtXUna5gZ+i1OZW1FZYVOIn8S+5bDC3ukd w==; X-CSE-ConnectionGUID: vT9irVkgQFKYOHJhUNayvg== X-CSE-MsgGUID: ywmevbmSRJO617a0/0XDMQ== X-IronPort-AV: E=McAfee;i="6800,10657,11678"; a="87896086" X-IronPort-AV: E=Sophos;i="6.21,246,1763452800"; d="scan'208";a="87896086" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 03:05:26 -0800 X-CSE-ConnectionGUID: TEiK8ZduT6Kkc2/9S1mGAQ== X-CSE-MsgGUID: WCugKZJLSvWb+W1RMf4Asw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,246,1763452800"; d="scan'208";a="237375547" Received: from bilal-nuc7i7bnh.iind.intel.com ([10.190.239.45]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 03:05:24 -0800 From: Mohammed Bilal To: igt-dev@lists.freedesktop.org Cc: kunal1.joshi@intel.com, sameer.lattannavar@intel.com, louis.chauvet@bootlin.com, Mohammed Bilal Subject: [PATCH i-g-t v5 3/5] lib/igt_kms: Add function to list connected connectors Date: Thu, 22 Jan 2026 16:33:58 +0530 Message-ID: <20260122110400.330188-4-mohammed.bilal@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20260122110400.330188-1-mohammed.bilal@intel.com> References: <20260122110400.330188-1-mohammed.bilal@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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" From: Louis Chauvet Introduce the igt_get_connected_connectors() function, which returns a list of connector IDs that are currently connected according to DRM. This function includes a timeout mechanism because connectors can be unplugged at any time. Also, especially with MST, the connector can be listed by drmModeGetResources() but not yet accessible with drmModeGetConnector(). Signed-off-by: Louis Chauvet Signed-off-by: Mohammed Bilal --- lib/igt_kms.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_kms.h | 1 + 2 files changed, 66 insertions(+) diff --git a/lib/igt_kms.c b/lib/igt_kms.c index 4eb3355c6..eb317a854 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -8024,6 +8024,29 @@ double igt_default_display_detect_timeout(void) return timeout; } +static drmModeConnectorPtr igt_wait_for_connector(int drm_fd, unsigned int connector_id, + double timeout) +{ + drmModeConnectorPtr connector = NULL; + struct timespec start, end; + + connector = drmModeGetConnector(drm_fd, connector_id); + /* + * This time is required as sometimes some id in the connector list are not totally + * ready or can disappear + */ + clock_gettime(CLOCK_MONOTONIC, &start); + end = start; + + while (!connector && + igt_time_elapsed(&start, &end) <= timeout) { + connector = drmModeGetConnector(drm_fd, connector_id); + clock_gettime(CLOCK_MONOTONIC, &end); + } + + return connector; +} + /** * igt_wait_for_connector_status: * @drm_fd: drm file descriptor @@ -8062,3 +8085,45 @@ bool igt_wait_for_connector_status(int drm_fd, unsigned int connector_id, double connector_id); return false; } + +/** + * igt_get_connected_connectors: + * + * @drm_fd: DRM file description + * @connector_ids: Out pointer for the list of connector ids connected. It must be freed by the + * caller. + * + * This will probe all the connectors and return the list of all + * connected connectors. + * Returns: The number of connectors in @connector_ids + */ +int igt_get_connected_connectors(int drm_fd, uint32_t **connector_ids) +{ + int connected_count = 0; + double timeout = igt_default_display_detect_timeout(); + drmModeResPtr resources; + + *connector_ids = NULL; + + resources = drmModeGetResources(drm_fd); + for (int j = 0; j < resources->count_connectors; j++) { + drmModeConnectorPtr connector = igt_wait_for_connector(drm_fd, + resources->connectors[j], + timeout); + + if (connector) { + if (connector->connection == DRM_MODE_CONNECTED) { + *connector_ids = reallocarray(*connector_ids, + connected_count + + 1, sizeof(**connector_ids)); + igt_assert(*connector_ids); + (*connector_ids)[connected_count] = resources->connectors[j]; + connected_count++; + } + drmModeFreeConnector(connector); + } + } + drmModeFreeResources(resources); + + return connected_count; +} diff --git a/lib/igt_kms.h b/lib/igt_kms.h index c95394034..bff8d0920 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -1315,5 +1315,6 @@ double igt_default_display_detect_timeout(void); 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); #endif /* __IGT_KMS_H__ */ -- 2.48.1