From: Erico Nunes <nunes.erico@gmail.com>
To: igt-dev@lists.freedesktop.org
Cc: anarsoul@gmail.com, yuq825@gmail.com, lima@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 2/3] lib/lima: Add lima helpers
Date: Wed, 24 May 2023 15:49:29 +0200 [thread overview]
Message-ID: <20230524134930.61911-3-nunes.erico@gmail.com> (raw)
In-Reply-To: <20230524134930.61911-1-nunes.erico@gmail.com>
Add initial gem helpers for lima tests, based on the panfrost ones.
Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
---
lib/igt_lima.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_lima.h | 26 +++++++++++++
lib/meson.build | 1 +
3 files changed, 124 insertions(+)
create mode 100644 lib/igt_lima.c
create mode 100644 lib/igt_lima.h
diff --git a/lib/igt_lima.c b/lib/igt_lima.c
new file mode 100644
index 00000000..0d0f3c80
--- /dev/null
+++ b/lib/igt_lima.c
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2023 Erico Nunes
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <signal.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+
+#include "drmtest.h"
+#include "igt_aux.h"
+#include "igt_core.h"
+#include "igt_lima.h"
+#include "ioctl_wrappers.h"
+#include "lima_drm.h"
+
+/**
+ * SECTION:igt_lima
+ * @short_description: LIMA support library
+ * @title: LIMA
+ * @include: igt.h
+ *
+ * This library provides various auxiliary helper functions for writing Lima
+ * tests.
+ */
+
+struct lima_bo *
+igt_lima_gem_new(int fd, size_t size)
+{
+ struct lima_bo *bo = calloc(1, sizeof(*bo));
+
+ struct drm_lima_gem_create create_bo = {
+ .size = size,
+ .flags = 0,
+ };
+
+ do_ioctl(fd, DRM_IOCTL_LIMA_GEM_CREATE, &create_bo);
+
+ bo->handle = create_bo.handle;
+ bo->size = size;
+ return bo;
+}
+
+void
+igt_lima_free_bo(int fd, struct lima_bo *bo)
+{
+ if (!bo)
+ return;
+
+ if (bo->map)
+ munmap(bo->map, bo->size);
+ gem_close(fd, bo->handle);
+ free(bo);
+}
+
+uint64_t
+igt_lima_get_bo_offset(int fd, uint32_t handle)
+{
+ struct drm_lima_gem_info gem_info = {
+ .handle = handle,
+ };
+
+ do_ioctl(fd, DRM_IOCTL_LIMA_GEM_INFO, &gem_info);
+
+ return gem_info.offset;
+}
+
+uint32_t
+igt_lima_get_param(int fd, int param)
+{
+ struct drm_lima_get_param get = {
+ .param = param,
+ };
+
+ do_ioctl(fd, DRM_IOCTL_LIMA_GET_PARAM, &get);
+
+ return get.value;
+}
+
+void *
+igt_lima_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned int prot)
+{
+ uint64_t offset = igt_lima_get_bo_offset(fd, handle);
+ void *ptr;
+
+ ptr = mmap(0, size, prot, MAP_SHARED, fd, offset);
+ if (ptr == MAP_FAILED)
+ return NULL;
+ else
+ return ptr;
+}
diff --git a/lib/igt_lima.h b/lib/igt_lima.h
new file mode 100644
index 00000000..83ca401f
--- /dev/null
+++ b/lib/igt_lima.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Erico Nunes
+ */
+
+#ifndef IGT_LIMA_H
+#define IGT_LIMA_H
+
+#include "lima_drm.h"
+
+struct lima_bo {
+ int handle;
+ uint64_t offset;
+ uint32_t size;
+ void *map;
+};
+
+struct lima_bo *igt_lima_gem_new(int fd, size_t size);
+void igt_lima_free_bo(int fd, struct lima_bo *bo);
+
+/* IOCTL wrappers */
+uint64_t igt_lima_get_bo_offset(int fd, uint32_t handle);
+uint32_t igt_lima_get_param(int fd, int param);
+void *igt_lima_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned int prot)
+
+#endif /* IGT_LIMA_H */
diff --git a/lib/meson.build b/lib/meson.build
index 85f100f7..a0f92941 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -89,6 +89,7 @@ lib_sources = [
'uwildmat/uwildmat.c',
'igt_kmod.c',
'igt_panfrost.c',
+ 'igt_lima.c',
'igt_v3d.c',
'igt_vc4.c',
'igt_vmwgfx.c',
--
2.40.1
next prev parent reply other threads:[~2023-05-24 13:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-24 13:49 [igt-dev] [PATCH i-g-t 0/3] Initial tests for the lima drm driver Erico Nunes
2023-05-24 13:49 ` [igt-dev] [PATCH i-g-t 1/3] lib: Add support for opening lima devices Erico Nunes
2023-05-24 13:49 ` Erico Nunes [this message]
2023-05-24 13:49 ` [igt-dev] [PATCH i-g-t 3/3] tests/lima: Add initial tests for lima Erico Nunes
2023-05-24 15:27 ` [igt-dev] ✗ Fi.CI.BUILD: failure for Initial tests for the lima drm driver Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230524134930.61911-3-nunes.erico@gmail.com \
--to=nunes.erico@gmail.com \
--cc=anarsoul@gmail.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=lima@lists.freedesktop.org \
--cc=yuq825@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox