Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t 0/3] Initial tests for the lima drm driver
@ 2023-05-24 13:49 Erico Nunes
  2023-05-24 13:49 ` [igt-dev] [PATCH i-g-t 1/3] lib: Add support for opening lima devices Erico Nunes
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Erico Nunes @ 2023-05-24 13:49 UTC (permalink / raw)
  To: igt-dev; +Cc: anarsoul, yuq825, lima

I started working on something for the lima drm driver and realized that
there is no coverage for it in igt yet. It would be nice to have some to
check the driver specific ioctls and support that work.
Here are some to get some basic support and if we can get these in, we
can follow up with more tests to cover the remaining ioctls.
I used the panfrost and v3d gem tests as a reference for these initial
tests.

Erico Nunes (3):
  lib: Add support for opening lima devices
  lib/lima: Add lima helpers
  tests/lima: Add initial tests for lima

 lib/drmtest.c        |  3 ++
 lib/drmtest.h        |  1 +
 lib/igt_lima.c       | 97 ++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_lima.h       | 26 ++++++++++++
 lib/meson.build      |  1 +
 tests/lima_gem_new.c | 78 +++++++++++++++++++++++++++++++++++
 tests/meson.build    |  1 +
 7 files changed, 207 insertions(+)
 create mode 100644 lib/igt_lima.c
 create mode 100644 lib/igt_lima.h
 create mode 100644 tests/lima_gem_new.c

-- 
2.40.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [igt-dev] [PATCH i-g-t 1/3] lib: Add support for opening lima devices
  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 ` Erico Nunes
  2023-05-24 13:49 ` [igt-dev] [PATCH i-g-t 2/3] lib/lima: Add lima helpers Erico Nunes
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Erico Nunes @ 2023-05-24 13:49 UTC (permalink / raw)
  To: igt-dev; +Cc: anarsoul, yuq825, lima

This will be to test the lima drm driver specific ioctls, so adding lima
to the list.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
---
 lib/drmtest.c | 3 +++
 lib/drmtest.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index aa2e6b08..677f411c 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -195,6 +195,7 @@ static const struct module {
 } modules[] = {
 	{ DRIVER_AMDGPU, "amdgpu" },
 	{ DRIVER_INTEL, "i915", modprobe_i915 },
+	{ DRIVER_LIMA, "lima" },
 	{ DRIVER_MSM, "msm" },
 	{ DRIVER_PANFROST, "panfrost" },
 	{ DRIVER_V3D, "v3d" },
@@ -596,6 +597,8 @@ static const char *chipset_to_str(int chipset)
 		return "xe";
 	case DRIVER_VMWGFX:
 		return "vmwgfx";
+	case DRIVER_LIMA:
+		return "lima";
 	case DRIVER_ANY:
 		return "any";
 	default:
diff --git a/lib/drmtest.h b/lib/drmtest.h
index ae86ee19..cedac89b 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -53,6 +53,7 @@
 #define DRIVER_MSM	(1 << 6)
 #define DRIVER_XE	(1 << 7)
 #define DRIVER_VMWGFX   (1 << 8)
+#define DRIVER_LIMA	(1 << 9)
 
 /*
  * Exclude DRVER_VGEM from DRIVER_ANY since if you run on a system
-- 
2.40.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [igt-dev] [PATCH i-g-t 2/3] lib/lima: Add lima helpers
  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
  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
  3 siblings, 0 replies; 5+ messages in thread
From: Erico Nunes @ 2023-05-24 13:49 UTC (permalink / raw)
  To: igt-dev; +Cc: anarsoul, yuq825, lima

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [igt-dev] [PATCH i-g-t 3/3] tests/lima: Add initial tests for lima
  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 ` [igt-dev] [PATCH i-g-t 2/3] lib/lima: Add lima helpers Erico Nunes
@ 2023-05-24 13:49 ` Erico Nunes
  2023-05-24 15:27 ` [igt-dev] ✗ Fi.CI.BUILD: failure for Initial tests for the lima drm driver Patchwork
  3 siblings, 0 replies; 5+ messages in thread
From: Erico Nunes @ 2023-05-24 13:49 UTC (permalink / raw)
  To: igt-dev; +Cc: anarsoul, yuq825, lima

Some gem tests based on the panfrost and v3d ones.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
---
 tests/lima_gem_new.c | 78 ++++++++++++++++++++++++++++++++++++++++++++
 tests/meson.build    |  1 +
 2 files changed, 79 insertions(+)
 create mode 100644 tests/lima_gem_new.c

diff --git a/tests/lima_gem_new.c b/tests/lima_gem_new.c
new file mode 100644
index 00000000..3b054317
--- /dev/null
+++ b/tests/lima_gem_new.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2023 Erico Nunes
+ */
+
+#include "igt.h"
+#include "igt_lima.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include "lima_drm.h"
+
+igt_main
+{
+	int fd;
+
+	igt_fixture {
+		fd = drm_open_driver(DRIVER_LIMA);
+	}
+
+	igt_describe("Sanity check for creating a BO with size 4096.");
+	igt_subtest("gem-new-4096") {
+		struct lima_bo *bo = igt_lima_gem_new(fd, 4096);
+
+		igt_lima_free_bo(fd, bo);
+	}
+
+	igt_describe("Make sure a BO cannot be created with size zero.");
+	igt_subtest("gem-new-0") {
+		struct drm_lima_gem_create arg = {
+			.size = 0,
+		};
+
+		do_ioctl_err(fd, DRM_IOCTL_LIMA_GEM_CREATE, &arg, EINVAL);
+	}
+
+	igt_describe("Make sure that BOs can be allocated in different fd without "
+		     "carrying old contents from one another.");
+	igt_subtest("gem-new-zeroed") {
+		int fd2 = drm_open_driver(DRIVER_LIMA);
+		struct lima_bo *bo;
+		uint32_t *map;
+		/* A size different from any used in our other tests, to try
+		 * to convince it to land as the only one of its size in the
+		 * kernel BO cache
+		 */
+		size_t size = 3 * 4096;
+		size_t i;
+
+		/* Make a BO and free it on our main fd. */
+		bo = igt_lima_gem_new(fd, size);
+		map = igt_lima_mmap_bo(fd, bo->handle, size, PROT_READ | PROT_WRITE);
+		memset(map, 0xd0, size);
+		munmap(map, size);
+		igt_lima_free_bo(fd, bo);
+
+		/* Now, allocate a BO on the other fd and make sure it doesn't
+		 * have the old contents.
+		 */
+		bo = igt_lima_gem_new(fd2, size);
+		map = igt_lima_mmap_bo(fd2, bo->handle, size, PROT_READ | PROT_WRITE);
+		for (i = 0; i < size / 4; i++)
+			igt_assert_eq_u32(map[i], 0x0);
+		munmap(map, size);
+		igt_lima_free_bo(fd2, bo);
+
+		close(fd2);
+	}
+
+	igt_fixture
+		close(fd);
+}
diff --git a/tests/meson.build b/tests/meson.build
index f71be1db..980e77e9 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -62,6 +62,7 @@ test_progs = [
 	'kms_vblank',
 	'kms_vrr',
 	'kms_writeback',
+	'lima_gem_new',
 	'meta_test',
 	'panfrost_get_param',
 	'panfrost_gem_new',
-- 
2.40.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [igt-dev] ✗ Fi.CI.BUILD: failure for Initial tests for the lima drm driver
  2023-05-24 13:49 [igt-dev] [PATCH i-g-t 0/3] Initial tests for the lima drm driver Erico Nunes
                   ` (2 preceding siblings ...)
  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 ` Patchwork
  3 siblings, 0 replies; 5+ messages in thread
From: Patchwork @ 2023-05-24 15:27 UTC (permalink / raw)
  To: Erico Nunes; +Cc: igt-dev

== Series Details ==

Series: Initial tests for the lima drm driver
URL   : https://patchwork.freedesktop.org/series/118303/
State : failure

== Summary ==

IGT patchset build failed on latest successful build
de4b71f2c13f6fdcae15a4c3fac7fbe5f5737685 intel_gpu_top: Move client name last

                 from ../../../usr/src/igt-gpu-tools/lib/igt_lima.c:20:
../../../usr/src/igt-gpu-tools/lib/i915/intel_memory_region.h:173:1: warning: empty declaration
  173 | struct gem_memory_region {
      | ^~~~~~
In file included from ../../../usr/src/igt-gpu-tools/lib/igt_lima.c:20:
../../../usr/src/igt-gpu-tools/lib/ioctl_wrappers.h:51:14: error: storage class specified for parameter ‘igt_ioctl’
   51 | extern int (*igt_ioctl)(int fd, unsigned long request, void *arg);
      |              ^~~~~~~~~
../../../usr/src/igt-gpu-tools/lib/ioctl_wrappers.h:120:1: warning: empty declaration
  120 | struct local_dma_buf_sync {
      | ^~~~~~
../../../usr/src/igt-gpu-tools/lib/ioctl_wrappers.h:168:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  168 | {
      | ^
../../../usr/src/igt-gpu-tools/lib/ioctl_wrappers.h:178:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  178 | {
      | ^
../../../usr/src/igt-gpu-tools/lib/ioctl_wrappers.h:188:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  188 | {
      | ^
../../../usr/src/igt-gpu-tools/lib/ioctl_wrappers.h:198:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  198 | {
      | ^
../../../usr/src/igt-gpu-tools/lib/igt_lima.c:35:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
   35 | {
      | ^
../../../usr/src/igt-gpu-tools/lib/igt_lima.c:52:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
   52 | {
      | ^
../../../usr/src/igt-gpu-tools/lib/igt_lima.c:64:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
   64 | {
      | ^
../../../usr/src/igt-gpu-tools/lib/igt_lima.c:76:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
   76 | {
      | ^
../../../usr/src/igt-gpu-tools/lib/igt_lima.c:88:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
   88 | {
      | ^
In file included from ../../../usr/src/igt-gpu-tools/lib/igt_lima.c:19:
../../../usr/src/igt-gpu-tools/lib/igt_lima.h:24:7: error: old-style parameter declarations in prototyped function definition
   24 | void *igt_lima_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned int prot)
      |       ^~~~~~~~~~~~~~~~
../../../usr/src/igt-gpu-tools/lib/igt_lima.c:97: error: expected ‘{’ at end of input
   97 | }
      | 
../../../usr/src/igt-gpu-tools/lib/igt_lima.c:97: error: control reaches end of non-void function [-Werror=return-type]
   97 | }
      | 
cc1: some warnings being treated as errors
ninja: build stopped: subcommand failed.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-24 15:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [igt-dev] [PATCH i-g-t 2/3] lib/lima: Add lima helpers Erico Nunes
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox