Add the necessary code needed to compile panthor tests as well as the
basic infrastructure that will be used by the Panthor tests themselves.

To make sure everything is in order, add a basic test in
panthor_query.c.

Signed-off-by: Daniel Almeida <daniel.alme...@collabora.com>
---
 lib/igt_panthor.c             | 41 +++++++++++++++++++++++++++++++++++
 lib/igt_panthor.h             | 12 ++++++++++
 lib/meson.build               |  1 +
 meson.build                   |  8 +++++++
 tests/meson.build             |  2 ++
 tests/panthor/meson.build     | 12 ++++++++++
 tests/panthor/panthor_query.c | 25 +++++++++++++++++++++
 7 files changed, 101 insertions(+)
 create mode 100644 lib/igt_panthor.c
 create mode 100644 lib/igt_panthor.h
 create mode 100644 tests/panthor/meson.build
 create mode 100644 tests/panthor/panthor_query.c

diff --git a/lib/igt_panthor.c b/lib/igt_panthor.c
new file mode 100644
index 000000000..0b690f796
--- /dev/null
+++ b/lib/igt_panthor.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: MIT
+// SPDX-FileCopyrightText: Copyright (C) 2025 Collabora Ltd.
+
+#include "drmtest.h"
+#include "igt_panthor.h"
+#include "ioctl_wrappers.h"
+#include "panthor_drm.h"
+
+/**
+ * SECTION:igt_panthor
+ * @short_description: Panthor support library
+ * @title: Panthor
+ * @include: igt.h
+ *
+ * This library provides various auxiliary helper functions for writing Panthor
+ * tests.
+ */
+
+/**
+ * igt_panthor_query:
+ * @fd: device file descriptor
+ * @type: query type (e.g., DRM_PANTHOR_DEV_QUERY_GPU_INFO)
+ * @data: pointer to a struct to store the query result
+ * @size: size of the result struct
+ * @err: expected error code, or 0 for success
+ *
+ * Query GPU information.
+ */
+void igt_panthor_query(int fd, int32_t type, void *data, size_t size, int err)
+{
+       struct drm_panthor_dev_query query = {
+               .type = type,
+               .pointer = (uintptr_t)data,
+               .size = size,
+       };
+
+       if (err)
+               do_ioctl_err(fd, DRM_IOCTL_PANTHOR_DEV_QUERY, &query, err);
+       else
+               do_ioctl(fd, DRM_IOCTL_PANTHOR_DEV_QUERY, &query);
+}
diff --git a/lib/igt_panthor.h b/lib/igt_panthor.h
new file mode 100644
index 000000000..a99b7102d
--- /dev/null
+++ b/lib/igt_panthor.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: MIT */
+/* SPDX-FileCopyrightText: Copyright (C) 2025 Collabora Ltd. */
+
+#ifndef IGT_PANTHOR_H
+#define IGT_PANTHOR_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+void igt_panthor_query(int fd, int32_t type, void *data, size_t size, int err);
+
+#endif /* IGT_PANTHOR_H */
diff --git a/lib/meson.build b/lib/meson.build
index f50a8d44b..4ccf3ee04 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -105,6 +105,7 @@ lib_sources = [
        'igt_kmod.c',
        'igt_ktap.c',
        'igt_panfrost.c',
+       'igt_panthor.c',
        'igt_v3d.c',
        'igt_vc4.c',
        'igt_vmwgfx.c',
diff --git a/meson.build b/meson.build
index f7ae427b3..56ef8730e 100644
--- a/meson.build
+++ b/meson.build
@@ -288,6 +288,7 @@ libexecdir = join_paths(get_option('libexecdir'), 
'igt-gpu-tools')
 amdgpudir = join_paths(libexecdir, 'amdgpu')
 msmdir = join_paths(libexecdir, 'msm')
 panfrostdir = join_paths(libexecdir, 'panfrost')
+panthordir = join_paths(libexecdir, 'panthor')
 v3ddir = join_paths(libexecdir, 'v3d')
 vc4dir = join_paths(libexecdir, 'vc4')
 vkmsdir = join_paths(libexecdir, 'vkms')
@@ -341,6 +342,12 @@ if get_option('use_rpath')
        endforeach
        panfrost_rpathdir = join_paths(panfrost_rpathdir, libdir)
 
+       panthor_rpathdir = '$ORIGIN'
+       foreach p : panthordir.split('/')
+               panthor_rpathdir = join_paths(panthor_rpathdir, '..')
+       endforeach
+       panthor_rpathdir = join_paths(panthor_rpathdir, libdir)
+
        v3d_rpathdir = '$ORIGIN'
        foreach p : v3ddir.split('/')
                v3d_rpathdir = join_paths(v3d_rpathdir, '..')
@@ -370,6 +377,7 @@ else
        amdgpudir_rpathdir = ''
        msm_rpathdir = ''
        panfrost_rpathdir = ''
+       panthor_rpathdir = ''
        v3d_rpathdir = ''
        vc4_rpathdir = ''
        vkms_rpathdir = ''
diff --git a/tests/meson.build b/tests/meson.build
index a7b9375ed..0b61561a4 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -486,6 +486,8 @@ subdir('msm')
 
 subdir('panfrost')
 
+subdir('panthor')
+
 subdir('v3d')
 
 subdir('vc4')
diff --git a/tests/panthor/meson.build b/tests/panthor/meson.build
new file mode 100644
index 000000000..ce13aebaa
--- /dev/null
+++ b/tests/panthor/meson.build
@@ -0,0 +1,12 @@
+panthor_progs = [
+       'panthor_query'
+]
+
+foreach prog : panthor_progs
+       test_executables += executable(prog, prog + '.c',
+                                      dependencies : test_deps,
+                                      install_dir : panthordir,
+                                      install_rpath : panthor_rpathdir,
+                                      install : true)
+       test_list += join_paths('panthor', prog)
+endforeach
diff --git a/tests/panthor/panthor_query.c b/tests/panthor/panthor_query.c
new file mode 100644
index 000000000..7c1055763
--- /dev/null
+++ b/tests/panthor/panthor_query.c
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: MIT
+// SPDX-FileCopyrightText: Copyright (C) 2025 Collabora Ltd.
+
+#include "igt.h"
+#include "igt_core.h"
+#include "igt_panthor.h"
+#include "panthor_drm.h"
+#include <stdint.h>
+
+igt_main {
+       int fd;
+
+       igt_fixture { fd = drm_open_driver(DRIVER_PANTHOR); }
+
+       igt_describe("Query GPU information from ROM.");
+       igt_subtest("query") {
+               struct drm_panthor_gpu_info gpu = {};
+
+               igt_panthor_query(fd, DRM_PANTHOR_DEV_QUERY_GPU_INFO, &gpu, 
sizeof(gpu), 0);
+
+               igt_assert(gpu.gpu_id != 0);
+       }
+
+       igt_fixture { drm_close_driver(fd); }
+}
-- 
2.51.0

Reply via email to