[igt-dev] [PATCH i-g-t v2 4/6] v3d: Add a helper library

Eric Anholt eric at anholt.net
Thu Nov 15 18:57:35 UTC 2018


Just a few little ioctl wrappers that v3d tests will use.

v2: Move the struct above the prototypes.

Signed-off-by: Eric Anholt <eric at anholt.net>
---
 lib/Makefile.sources |   2 +
 lib/drmtest.c        |   3 +
 lib/drmtest.h        |   1 +
 lib/igt_v3d.c        | 130 +++++++++++++++++++++++++++++++++++++++++++
 lib/igt_v3d.h        |  46 +++++++++++++++
 lib/meson.build      |   1 +
 6 files changed, 183 insertions(+)
 create mode 100644 lib/igt_v3d.c
 create mode 100644 lib/igt_v3d.h

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index e98989ff8ed9..808b9617eca2 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -107,6 +107,8 @@ lib_source_list =	 	\
 	igt_syncobj.h		\
 	igt_psr.c		\
 	igt_psr.h		\
+	igt_v3d.c		\
+	igt_v3d.h		\
 	$(NULL)
 
 .PHONY: version.h.tmp
diff --git a/lib/drmtest.c b/lib/drmtest.c
index fee9d33ad2a5..d2aa1c19154f 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -202,6 +202,7 @@ static const struct module {
 } modules[] = {
 	{ DRIVER_AMDGPU, "amdgpu" },
 	{ DRIVER_INTEL, "i915", modprobe_i915 },
+	{ DRIVER_V3D, "v3d" },
 	{ DRIVER_VC4, "vc4" },
 	{ DRIVER_VGEM, "vgem" },
 	{ DRIVER_VIRTIO, "virtio-gpu" },
@@ -340,6 +341,8 @@ static const char *chipset_to_str(int chipset)
 	switch (chipset) {
 	case DRIVER_INTEL:
 		return "intel";
+	case DRIVER_V3D:
+		return "v3d";
 	case DRIVER_VC4:
 		return "vc4";
 	case DRIVER_VGEM:
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 949865ee54dd..96ee517e2ec1 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -43,6 +43,7 @@
 #define DRIVER_VGEM	(1 << 2)
 #define DRIVER_VIRTIO	(1 << 3)
 #define DRIVER_AMDGPU	(1 << 4)
+#define DRIVER_V3D	(1 << 5)
 /*
  * Exclude DRVER_VGEM from DRIVER_ANY since if you run on a system
  * with vgem as well as a supported driver, you can end up with a
diff --git a/lib/igt_v3d.c b/lib/igt_v3d.c
new file mode 100644
index 000000000000..1a5ede1bd5fc
--- /dev/null
+++ b/lib/igt_v3d.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright © 2016 Broadcom
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#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_v3d.h"
+#include "ioctl_wrappers.h"
+#include "intel_reg.h"
+#include "intel_chipset.h"
+#include "v3d_drm.h"
+
+#if NEW_CONTEXT_PARAM_NO_ERROR_CAPTURE_API
+#define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4
+#endif
+
+/**
+ * SECTION:igt_v3d
+ * @short_description: V3D support library
+ * @title: V3D
+ * @include: igt.h
+ *
+ * This library provides various auxiliary helper functions for writing V3D
+ * tests.
+ */
+
+struct v3d_bo *
+igt_v3d_create_bo(int fd, size_t size)
+{
+	struct v3d_bo *bo = calloc(1, sizeof(*bo));
+
+	struct drm_v3d_create_bo create = {
+		.size = size,
+	};
+
+	do_ioctl(fd, DRM_IOCTL_V3D_CREATE_BO, &create);
+
+	bo->handle = create.handle;
+	bo->offset = create.offset;
+	bo->size = size;
+
+	return bo;
+}
+
+void
+igt_v3d_free_bo(int fd, struct v3d_bo *bo)
+{
+	if (bo->map)
+		munmap(bo->map, bo->size);
+	gem_close(fd, bo->handle);
+	free(bo);
+}
+
+uint32_t
+igt_v3d_get_bo_offset(int fd, uint32_t handle)
+{
+	struct drm_v3d_get_bo_offset get = {
+		.handle = handle,
+	};
+
+	do_ioctl(fd, DRM_IOCTL_V3D_GET_BO_OFFSET, &get);
+
+	return get.offset;
+}
+
+uint32_t
+igt_v3d_get_param(int fd, enum drm_v3d_param param)
+{
+	struct drm_v3d_get_param get = {
+		.param = param,
+	};
+
+	do_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &get);
+
+	return get.value;
+}
+
+void *
+igt_v3d_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot)
+{
+	struct drm_v3d_mmap_bo mmap_bo = {
+		.handle = handle,
+	};
+	void *ptr;
+
+	do_ioctl(fd, DRM_IOCTL_V3D_MMAP_BO, &mmap_bo);
+
+	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_bo.offset);
+	if (ptr == MAP_FAILED)
+		return NULL;
+	else
+		return ptr;
+}
+
+void igt_v3d_bo_mmap(int fd, struct v3d_bo *bo)
+{
+	bo->map = igt_v3d_mmap_bo(fd, bo->handle, bo->size,
+				  PROT_READ | PROT_WRITE);
+	igt_assert(bo->map);
+}
diff --git a/lib/igt_v3d.h b/lib/igt_v3d.h
new file mode 100644
index 000000000000..2042995103cc
--- /dev/null
+++ b/lib/igt_v3d.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2016 Broadcom
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef IGT_V3D_H
+#define IGT_V3D_H
+
+#include "v3d_drm.h"
+
+struct v3d_bo {
+	int handle;
+	uint32_t offset;
+	uint32_t size;
+	void *map;
+};
+
+struct v3d_bo *igt_v3d_create_bo(int fd, size_t size);
+void igt_v3d_free_bo(int fd, struct v3d_bo *bo);
+
+/* IOCTL wrappers */
+uint32_t igt_v3d_get_bo_offset(int fd, uint32_t handle);
+uint32_t igt_v3d_get_param(int fd, enum drm_v3d_param param);
+void *igt_v3d_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot);
+
+void igt_v3d_bo_mmap(int fd, struct v3d_bo *bo);
+
+#endif /* IGT_V3D_H */
diff --git a/lib/meson.build b/lib/meson.build
index 8961ca494af8..19f5d51ceead 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -48,6 +48,7 @@ lib_sources = [
 	'igt_dummyload.c',
 	'uwildmat/uwildmat.c',
 	'igt_kmod.c',
+	'igt_v3d.c',
 	'igt_vc4.c',
 	'igt_psr.c',
 ]
-- 
2.19.1



More information about the igt-dev mailing list