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 839FBE7DEF3 for ; Mon, 2 Feb 2026 14:32:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2E89510E4EE; Mon, 2 Feb 2026 14:32:47 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="xa0D0S5g"; dkim-atps=neutral Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2861110E4EE for ; Mon, 2 Feb 2026 14:32:46 +0000 (UTC) Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 1B81D1A2C1B for ; Mon, 2 Feb 2026 14:32:45 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id E6A4260767; Mon, 2 Feb 2026 14:32:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8DCE2119A8903; Mon, 2 Feb 2026 15:32:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1770042764; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=tqRWrfH/Q+QyIau282vwrbCo1QBLh7F6NSRvohVFFiQ=; b=xa0D0S5ghgK4dAVh6zTzVlDq0DGIUXyLxHr4Iar3X7Tnuu4ps8zrD07xw06of0IFWVEXun W5ASQ2lAOHy9JFv+TXsJ1nASWcZ/HsjBdEUw8CtjIGu14DRWgbfKLaEaUHV3ZvYatAOyLu 0YePoccdU1kP15VxsDkEfeX/U7dhobByBsodTv8qIy/AN4/pdYsZ1KO6NotM9r1j63nLvu FTYtuylpEHZfKd5sheUJIbTSWpgeBXrIthVFUM+rVdfdJyXJ53Ww5patKiOV3R41QlAl+2 Zll0tbwNTEJxPV6X5VMS/dZjwzQ/Xvyx093oFU6zMtYGCDajIEk83jcwvFpr9g== From: Louis Chauvet Date: Mon, 02 Feb 2026 15:32:58 +0100 Subject: [PATCH i-g-t v6 19/48] lib/unigraf: Initial Unigraf support MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260202-unigraf-integration-v6-19-834af822eee7@bootlin.com> References: <20260202-unigraf-integration-v6-0-834af822eee7@bootlin.com> In-Reply-To: <20260202-unigraf-integration-v6-0-834af822eee7@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=7446; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=7c+BTN3JtJOzAV0T4O8XS3UVvGE6b2ijRv+WlMfdib8=; b=owEBiQJ2/ZANAwAIASCtLsZbECziAcsmYgBpgLWR6JoFtqrsc33bp3VneBIJODkp9D9nzC2sR I58/+XUt9qJAk8EAAEIADkWIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCaYC1kRsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMSwyLDIACgkQIK0uxlsQLOJimQ/+KfjZTS+8ATFlaeF/Hpo2U6f0V9/njJ7 Ixbl6DeSAuy6Pn+1v33Or/FUj6XW2Va5WU1663hn4zc3SB9LCqWe7nKfoJllWCCqXidwW/3UqEx KOzjD0Q2/bWyc9zsSbL6M4PO8Lx6RkdAVGHn8PNixXuKUbQ/rBn1VCCSHoXy22ilMKQ+ssu2IN/ ExgL8ir0cW1LtI6cI5Sv+E5PfXPIu9bCddzwRCQDQUY0A1bTtlxrmHy37nRMnuMcTf877m6+/xa weNu+Fm1jl/auG4G5YP+xnrVJHl5suTgltigFe8cEWLeD/TM+jootc9KB+R2F8Nq4f1+PfMzJmU 4hyPH4yJ8b/fVKtYEorNcdZuKdxMB/W8PQ31xRaceaW181DfFqW93ZhrCbgsxrQ9+td5FFMZcVg qkY+3riU1n1+OwxGHUClOttBIzmugfog9SBSjqAthSnGzEChADkZ359L2zlo5qP8qnfzQpQmmbq K+PHjKF3dkfN/F6YXp0tVFAfNF0yDQn9nDqA+W1uG7LdcC0F/AmWk5ANhsvRiWx1ggu8KQXw0nm XVQu9nodqG76nNZxHuhTlO4ypuQPMupiRlfSr1UA8nK/vO/LoXfz4xY3do7KxKuFnzJjhkQXwyP 0pyL7j3oC4rhOUF+srE5fBdVaP9KoUICG5P0D6X8En5cQP0IhOpM= 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" This introduce the basic boilerplate to connect to a unigraf device. This integration currently only supports one device openned to simplify its usage and cleanup. The functions unigraf_open_device and unigraf_require_device will register a handler to do proper cleanup on IGT exit. Signed-off-by: Louis Chauvet --- lib/meson.build | 10 +++++ lib/unigraf/unigraf.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/unigraf/unigraf.h | 37 ++++++++++++++++ meson.build | 14 +++++++ 4 files changed, 175 insertions(+) diff --git a/lib/meson.build b/lib/meson.build index d851029e04ef..346764902c4e 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -150,6 +150,13 @@ lib_deps = [ zlib ] +if libtsi.found() + lib_deps += libtsi + lib_sources += [ + 'unigraf/unigraf.c' + ] +endif + if libdrm_nouveau.found() lib_deps += libdrm_nouveau lib_sources += [ @@ -230,6 +237,9 @@ endif if chamelium.found() lib_deps += chamelium lib_sources += [ 'igt_chamelium.c', 'igt_chamelium_stream.c' ] +endif + +if chamelium.found() or libtsi.found() lib_sources += 'monitor_edids/monitor_edids_helper.c' endif diff --git a/lib/unigraf/unigraf.c b/lib/unigraf/unigraf.c new file mode 100644 index 000000000000..3318c95fbbb6 --- /dev/null +++ b/lib/unigraf/unigraf.c @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: MIT + +#include "igt_core.h" +#include + +#include "unigraf.h" +#include "TSI.h" +#include "TSI_types.h" + +#define unigraf_debug(fmt, ...) igt_debug("TSI:%p: " fmt, unigraf_device, ##__VA_ARGS__) + +static TSI_HANDLE unigraf_device; +static char *unigraf_default_edid; +static char *unigraf_connector_name; + +static void unigraf_close_device(void) +{ + if (!unigraf_device) + return; + + unigraf_debug("Closing...\n"); + unigraf_assert(TSIX_DEV_CloseDevice(unigraf_device)); + TSI_Clean(); + unigraf_device = NULL; + free(unigraf_default_edid); + free(unigraf_connector_name); +} + +/** + * unigraf_exit_handler - Handle the exit signal and clean up unigraf resources. + * @sig: The signal number received. + * + * This function is called when the program receives an exit signal. It ensures + * that all unigraf resources are properly cleaned up by calling unigraf_deinit + * for each open instance. + */ +static void unigraf_exit_handler(int sig) +{ + unigraf_close_device(); +} + +static void unigraf_init(void) +{ + int ret; + + unigraf_debug("Initialize unigraf...\n"); + ret = TSI_Init(TSI_CURRENT_VERSION); + unigraf_assert(ret); + igt_install_exit_handler(unigraf_exit_handler); +} + +/** + * unigraf_device_count() - Return the number of scanned devices + * + * Must be called after a unigraf_rescan_devices(). + */ +static unsigned int unigraf_device_count(void) +{ + return unigraf_assert(TSIX_DEV_GetDeviceCount()); +} + +/** + * unigraf_open_device() - Search and open a device. + * @drm_fd: File descriptor of the currently used drm device + * + * Returns: true if a device was found and initialized, otherwise false. + * + * This function searches for a compatible device and opens it. + */ +bool unigraf_open_device(int drm_fd) +{ + TSI_RESULT r; + int device_count; + int chosen_device = 0; + int chosen_role = 0; + int chosen_input = 0; + + assert(igt_can_fail()); + + if (unigraf_device) + return true; + + unigraf_init(); + + unigraf_assert(TSIX_DEV_RescanDevices(0, TSI_DEVCAP_VIDEO_CAPTURE, 0)); + + device_count = unigraf_device_count(); + if (device_count < 1) { + unigraf_debug("No device found.\n"); + return false; + } + + unigraf_device = TSIX_DEV_OpenDevice(chosen_device, &r); + unigraf_assert(r); + igt_assert(unigraf_device); + unigraf_debug("Successfully opened the unigraf device %d.\n", chosen_device); + + unigraf_assert(TSIX_DEV_SelectRole(unigraf_device, chosen_role)); + unigraf_assert(TSIX_VIN_Select(unigraf_device, chosen_input)); + unigraf_assert(TSIX_VIN_Enable(unigraf_device, chosen_input)); + + return true; +} + +/** + * unigraf_require_device() - Search and open a device. + * @drm_fd: File descriptor of the currently used drm device + * + * This is a shorthand to reduce test boilerplate when a unigraf device must be present. + */ +void unigraf_require_device(int drm_fd) +{ + igt_require(unigraf_open_device(drm_fd)); +} diff --git a/lib/unigraf/unigraf.h b/lib/unigraf/unigraf.h new file mode 100644 index 000000000000..376ed910bfa8 --- /dev/null +++ b/lib/unigraf/unigraf.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: MIT */ + +#ifndef UNIGRAF_H +#define UNIGRAF_H + +#include +#include + +/** + * unigraf_assert: Helper macro to assert a TSI return value and retrieve a detailed error message. + * @result: libTSI return value to check + * + * This macro checks the return value of a libTSI function call. If the return value indicates an + * error, it retrieves a detailed error message and asserts with that message. + * If retrieving the error description fails, it asserts with a generic error message. + */ +#define unigraf_assert(result) \ +({ \ + char msg[256]; \ + TSI_RESULT __r = (result); \ + if (__r < TSI_SUCCESS) { \ + TSI_RESULT __r2 = TSI_MISC_GetErrorDescription(__r, msg, sizeof(msg)); \ + if (__r2 < TSI_SUCCESS) \ + igt_assert_f(false, \ + "unigraf error: %d (get error description failed: %d)\n", \ + __r, __r2); \ + else \ + igt_assert_f(false, "unigraf error: %d (%s)\n", __r, msg); \ + } \ + (__r); \ +}) + +bool unigraf_open_device(int drm_fd); + +void unigraf_require_device(int drm_fd); + +#endif // UNIGRAF_H diff --git a/meson.build b/meson.build index 4b2496c01679..ff197cec314d 100644 --- a/meson.build +++ b/meson.build @@ -165,6 +165,12 @@ cairo = dependency('cairo', version : '>1.12.0', required : true) libudev = dependency('libudev', required : true) glib = dependency('glib-2.0', required : true) +libtsi = cc.find_library('TSI', required : false) + +if libtsi.found() + config.set('HAVE_UNIGRAF', 1) +endif + xmlrpc = dependency('xmlrpc', required : false) xmlrpc_util = dependency('xmlrpc_util', required : false) xmlrpc_client = dependency('xmlrpc_client', required : false) @@ -289,6 +295,7 @@ amdgpudir = join_paths(libexecdir, 'amdgpu') msmdir = join_paths(libexecdir, 'msm') panfrostdir = join_paths(libexecdir, 'panfrost') panthordir = join_paths(libexecdir, 'panthor') +unigrafdir = join_paths(libexecdir, 'unigraf') v3ddir = join_paths(libexecdir, 'v3d') vc4dir = join_paths(libexecdir, 'vc4') vkmsdir = join_paths(libexecdir, 'vkms') @@ -371,6 +378,12 @@ if get_option('use_rpath') vmwgfx_rpathdir = join_paths(vmwgfx_rpathdir, '..') endforeach vmwgfx_rpathdir = join_paths(vmwgfx_rpathdir, libdir) + + unigraf_rpathdir = '$ORIGIN' + foreach p : unigrafdir.split('/') + unigraf_rpathdir = join_paths(unigraf_rpathdir, '..') + endforeach + unigraf_rpathdir = join_paths(unigraf_rpathdir, libdir) else bindir_rpathdir = '' libexecdir_rpathdir = '' @@ -382,6 +395,7 @@ else vc4_rpathdir = '' vkms_rpathdir = '' vmwgfx_rpathdir = '' + unigraf_rpathdir = '' endif build_testplan = get_option('testplan') -- 2.52.0