Skip to contentSkip to conversation

Initial tests for the lima drm driver

PATCH Superseded Erico Nunes 2 participants 5 messages May 24, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Initial tests for the lima drm driver

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
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/3 lib: Add support for opening lima devices

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

---
 lib/drmtest.c | 3 +++
 lib/drmtest.h | 1 +
 2 files changed, 4 insertions(+)
lib/drmtest.c +3 -0
index aa2e6b08..677f411c 100644
@@ -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:
lib/drmtest.h +1 -0
index ae86ee19..cedac89b 100644
@@ -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
Signature · 1 line
2.40.1
#2 lore raw

PATCH 2/3 lib/lima: Add lima helpers

In reply to Erico Nunes

Add initial gem helpers for lima tests, based on the panfrost ones.

---
 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
lib/igt_lima.c new file +97 -0
new file mode 100644
index 00000000..0d0f3c80
@@ -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;
+}
lib/igt_lima.h new file +26 -0
new file mode 100644
index 00000000..83ca401f
@@ -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 */
lib/meson.build +1 -0
index 85f100f7..a0f92941 100644
@@ -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',
Signature · 1 line
2.40.1
#3 lore raw

PATCH 3/3 tests/lima: Add initial tests for lima

In reply to Erico Nunes

Some gem tests based on the panfrost and v3d ones.

---
 tests/lima_gem_new.c | 78 ++++++++++++++++++++++++++++++++++++++++++++
 tests/meson.build    |  1 +
 2 files changed, 79 insertions(+)
 create mode 100644 tests/lima_gem_new.c
tests/lima_gem_new.c new file +78 -0
new file mode 100644
index 00000000..3b054317
@@ -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);
+}
tests/meson.build +1 -0
index f71be1db..980e77e9 100644
@@ -62,6 +62,7 @@ test_progs = [
 	'kms_vblank',
 	'kms_vrr',
 	'kms_writeback',
+	'lima_gem_new',
 	'meta_test',
 	'panfrost_get_param',
 	'panfrost_gem_new',
Signature · 1 line
2.40.1
#4 lore raw

[igt-dev] ✗ Fi.CI.BUILD: failure for Initial tests for the lima drm driver

In reply to Erico Nunes
== Series Details ==

== 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.