All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Robert M. Fosha" <robert.m.fosha@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Sally Qi <feng.qi@intel.com>
Subject: [igt-dev] [PATCH i-g-t v2] tests/i915/gem_huc_copy: Enable a HuC copy test
Date: Fri, 20 Dec 2019 14:41:35 -0800	[thread overview]
Message-ID: <20191220224135.4595-1-robert.m.fosha@intel.com> (raw)
In-Reply-To: <20191219235047.15224-1-robert.m.fosha@intel.com>

From: Sally Qi <feng.qi@intel.com>

This test case loads the HuC copy firmware to copy the content of
the source buffer to the destination buffer.

v2: (Tony Ye)
 * Restructured some functions and files.
 * Defined the copy buffer size as 4K explicitly as the HuC Copy kernel
   always copy 4K bytes from src buffer to dst buffer.

v3: (Feng Qi, Antonio Argenziano, Tony Ye)
 * Restructured some functions as igt requested, exclude libdrm function call.
 * Remove huc function wrappers
 * Random initialize source input buffer

v4:
 * Fix autotools build failure.

Signed-off-by: Sally Qi <feng.qi@intel.com>
Signed-off-by: Tony Ye <tony.ye@intel.com>
Acked-by: Antonio Argenziano <antonio.argenziano@intel.com>
---
 lib/Makefile.sources      |   2 +
 lib/huc_copy.c            | 109 +++++++++++++++++++++++++++++++++++++
 lib/huc_copy.h            |  51 ++++++++++++++++++
 lib/intel_batchbuffer.c   |  20 +++++++
 lib/intel_batchbuffer.h   |  19 +++++++
 lib/meson.build           |   1 +
 tests/Makefile.sources    |   3 ++
 tests/i915/gem_huc_copy.c | 111 ++++++++++++++++++++++++++++++++++++++
 tests/meson.build         |   1 +
 9 files changed, 317 insertions(+)
 create mode 100644 lib/huc_copy.c
 create mode 100644 lib/huc_copy.h
 create mode 100644 tests/i915/gem_huc_copy.c

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index 5dd3962e..e9e132c1 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -78,6 +78,8 @@ lib_source_list =	 	\
 	ioctl_wrappers.h	\
 	media_fill.c		\
 	media_fill.h            \
+	huc_copy.c		\
+	huc_copy.h		\
 	media_spin.h		\
 	media_spin.c		\
 	gpgpu_fill.h		\
diff --git a/lib/huc_copy.c b/lib/huc_copy.c
new file mode 100644
index 00000000..32541157
--- /dev/null
+++ b/lib/huc_copy.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright © 2019 Intel Corporation
+ *
+ * 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 <i915_drm.h>
+#include "huc_copy.h"
+
+static void
+gen9_emit_huc_virtual_addr_state(struct drm_i915_gem_exec_object2 *src,
+		struct drm_i915_gem_exec_object2 *dst,
+		struct drm_i915_gem_relocation_entry *reloc_src,
+		struct drm_i915_gem_relocation_entry *reloc_dst,
+		uint32_t *buf,
+		int *i)
+{
+	buf[(*i)++] = HUC_VIRTUAL_ADDR_STATE;
+
+	for (int j = 0; j < HUC_VIRTUAL_ADDR_REGION_NUM; j++) {
+		if (j == HUC_VIRTUAL_ADDR_REGION_SRC) {
+			buf[(*i)++] = src->offset;
+
+			reloc_src->target_handle = src->handle;
+			reloc_src->delta = 0;
+			reloc_src->offset = (*i - 1) * sizeof(buf[0]);
+			reloc_src->read_domains = 0;
+			reloc_src->write_domain = 0;
+		} else if (j == HUC_VIRTUAL_ADDR_REGION_DST) {
+			buf[(*i)++] = dst->offset;
+
+			reloc_dst->target_handle = dst->handle;
+			reloc_dst->delta = 0;
+			reloc_dst->offset = (*i - 1) * sizeof(buf[0]);
+			reloc_dst->read_domains = 0;
+			reloc_dst->write_domain = I915_GEM_DOMAIN_RENDER;
+		} else {
+			buf[(*i)++] = 0;
+		}
+		buf[(*i)++] = 0;
+		buf[(*i)++] = 0;
+	}
+}
+
+void
+gen9_huc_copyfunc(int fd,
+		struct drm_i915_gem_exec_object2 *src,
+		struct drm_i915_gem_exec_object2 *dst,
+		struct drm_i915_gem_exec_object2 *exec)
+{
+	struct drm_i915_gem_relocation_entry reloc[2];
+	struct drm_i915_gem_execbuffer2 execbuf;
+	int i = 0;
+	uint32_t buf[63];
+
+	/* load huc kernel */
+	buf[i++] = HUC_IMEM_STATE;
+	buf[i++] = 0;
+	buf[i++] = 0;
+	buf[i++] = 0;
+	buf[i++] = 0x3;
+
+	buf[i++] = MFX_WAIT;
+	buf[i++] = MFX_WAIT;
+
+	buf[i++] = HUC_PIPE_MODE_SELECT;
+	buf[i++] = 0;
+	buf[i++] = 0;
+
+	buf[i++] = MFX_WAIT;
+
+	memset(reloc, 0, sizeof(reloc));
+	gen9_emit_huc_virtual_addr_state(src, dst, &reloc[0], &reloc[1], buf, &i);
+
+	buf[i++] = HUC_START;
+	buf[i++] = 1;
+
+	buf[i++] = MI_BATCH_BUFFER_END;
+
+	gem_write(fd, exec->handle, 0, buf, sizeof(buf));
+	exec->relocation_count = 2;
+	exec->relocs_ptr = to_user_pointer(reloc);
+
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = to_user_pointer(src);
+	execbuf.buffer_count = 3;
+	execbuf.flags = I915_EXEC_BSD;
+
+	gem_execbuf(fd, &execbuf);
+	gem_close(fd, exec->handle);
+}
diff --git a/lib/huc_copy.h b/lib/huc_copy.h
new file mode 100644
index 00000000..c435f6cb
--- /dev/null
+++ b/lib/huc_copy.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2019 Intel Corporation
+ *
+ * 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 HUC_COPY_H
+#define HUC_COPY_H
+
+#include <stdint.h>
+#include <string.h>
+#include "ioctl_wrappers.h"
+#include "intel_reg.h"
+
+#define PARALLEL_VIDEO_PIPE		(0x3<<29)
+#define MFX_WAIT			(PARALLEL_VIDEO_PIPE|(0x1<<27)|(0x1<<8))
+
+#define HUC_IMEM_STATE			(PARALLEL_VIDEO_PIPE|(0x2<<27)|(0xb<<23)|(0x1<<16)|0x3)
+#define HUC_PIPE_MODE_SELECT		(PARALLEL_VIDEO_PIPE|(0x2<<27)|(0xb<<23)|0x1)
+#define HUC_START			(PARALLEL_VIDEO_PIPE|(0x2<<27)|(0xb<<23)|(0x21<<16))
+#define HUC_VIRTUAL_ADDR_STATE		(PARALLEL_VIDEO_PIPE|(0x2<<27)|(0xb<<23)|(0x4<<16)|0x2f)
+
+#define HUC_VIRTUAL_ADDR_REGION_NUM	16
+#define HUC_VIRTUAL_ADDR_REGION_SRC	0
+#define HUC_VIRTUAL_ADDR_REGION_DST	14
+
+void
+gen9_huc_copyfunc(int fd,
+		struct drm_i915_gem_exec_object2 *src,
+		struct drm_i915_gem_exec_object2 *dst,
+		struct drm_i915_gem_exec_object2 *exec);
+
+#endif /* HUC_COPY_H */
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index 51aae4dc..d8cb9df3 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -43,6 +43,7 @@
 #include "ioctl_wrappers.h"
 #include "media_spin.h"
 #include "gpgpu_fill.h"
+#include "huc_copy.h"
 
 #include <i915_drm.h>
 
@@ -942,3 +943,22 @@ igt_media_spinfunc_t igt_get_media_spinfunc(int devid)
 
 	return spin;
 }
+
+/**
+ * igt_get_huc_copyfunc:
+ * @devid: pci device id
+ *
+ * Returns:
+ *
+ * The platform-specific huc copy function pointer for the device specified
+ * with @devid. Will return NULL when no media spin function is implemented.
+ */
+igt_huc_copyfunc_t igt_get_huc_copyfunc(int devid)
+{
+	igt_huc_copyfunc_t copy = NULL;
+
+	if (IS_GEN12(devid) || IS_GEN11(devid) || IS_GEN9(devid))
+		copy = gen9_huc_copyfunc;
+
+	return copy;
+}
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 37e3affe..5af585ed 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -388,4 +388,23 @@ typedef void (*igt_media_spinfunc_t)(struct intel_batchbuffer *batch,
 
 igt_media_spinfunc_t igt_get_media_spinfunc(int devid);
 
+/**
+ * igt_huc_copyfunc_t:
+ * @fd: drm fd
+ * @src: source drm buffer
+ * @dst: destination drm buffer
+ * @exec: execution drm buffer
+ *
+ * This is the type of the per-platform huc copy functions.
+ *
+ * The huc copy function emits a batchbuffer to the VDBOX engine to
+ * invoke the HuC Copy kernel to copy 4K bytes from the source buffer
+ * to the destination buffer.
+ */
+typedef void (*igt_huc_copyfunc_t)(int fd,
+		struct drm_i915_gem_exec_object2 *src,
+		struct drm_i915_gem_exec_object2 *dst,
+		struct drm_i915_gem_exec_object2 *exec);
+
+igt_huc_copyfunc_t	igt_get_huc_copyfunc(int devid);
 #endif
diff --git a/lib/meson.build b/lib/meson.build
index 57eb7d93..3d720683 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -1,5 +1,6 @@
 lib_sources = [
 	'drmtest.c',
+	'huc_copy.c',
 	'i915/gem_context.c',
 	'i915/gem_engine_topology.c',
 	'i915/gem_scheduler.c',
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 806eb02d..d230d6b4 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -313,6 +313,9 @@ gem_media_fill_SOURCES = i915/gem_media_fill.c
 TESTS_progs += gem_media_vme
 gem_media_vme_SOURCES = i915/gem_media_vme.c
 
+TESTS_progs += gem_huc_copy
+gem_huc_copy_SOURCES = i915/gem_huc_copy.c
+
 TESTS_progs += gem_mmap
 gem_mmap_SOURCES = i915/gem_mmap.c
 
diff --git a/tests/i915/gem_huc_copy.c b/tests/i915/gem_huc_copy.c
new file mode 100644
index 00000000..f8da115d
--- /dev/null
+++ b/tests/i915/gem_huc_copy.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright © 2019 Intel Corporation
+ *
+ * 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 "igt.h"
+#include <stdbool.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include "drm.h"
+
+IGT_TEST_DESCRIPTION("A very simple workload for the HuC.");
+
+#define HUC_COPY_DATA_BUF_SIZE	4096
+
+static void
+compare_huc_copy_result(int drm_fd, uint32_t src_handle, uint32_t dst_handle)
+{
+	char src_output[HUC_COPY_DATA_BUF_SIZE];
+	char dst_output[HUC_COPY_DATA_BUF_SIZE];
+
+	gem_read(drm_fd, src_handle, 0, src_output, HUC_COPY_DATA_BUF_SIZE);
+	gem_read(drm_fd, dst_handle, 0, dst_output, HUC_COPY_DATA_BUF_SIZE);
+
+	for (int i = 0; i < HUC_COPY_DATA_BUF_SIZE; i++) {
+		igt_assert_f(src_output[i] == dst_output[i],
+				"Huc Copy failed!\n");
+	}
+}
+
+static bool
+check_huc_status(int fd)
+{
+	int val = 0;
+	struct drm_i915_getparam pg;
+
+	pg.param = I915_PARAM_HUC_STATUS;
+	pg.value = &val;
+	if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &pg) == 0) {
+		return !!val;
+	} else {
+		return 0;
+	}
+}
+
+igt_main
+{
+	int drm_fd = -1;
+	uint32_t devid;
+	igt_huc_copyfunc_t huc_copy;
+
+	igt_fixture {
+		drm_fd = drm_open_driver(DRIVER_INTEL);
+		igt_require_gem(drm_fd);
+		devid = intel_get_drm_devid(drm_fd);
+		huc_copy = igt_get_huc_copyfunc(devid);
+		igt_require_f(huc_copy, "no huc_copy function\n");
+		igt_assert_f(check_huc_status(drm_fd) == true,
+			"HuC is not successfully loaded!\n");
+	}
+
+	igt_subtest_f("huc-copy") {
+		char inputs[HUC_COPY_DATA_BUF_SIZE];
+		struct drm_i915_gem_exec_object2 obj[3];
+
+		/* Initialize src buffer randomly */
+		srand(time(NULL));
+		for (int i = 0; i < HUC_COPY_DATA_BUF_SIZE; i++) {
+			inputs[i] = (char) (rand() % 256);
+		}
+
+		memset(obj, 0, sizeof(obj));
+		obj[0].handle = gem_create(drm_fd, HUC_COPY_DATA_BUF_SIZE);
+		obj[1].handle = gem_create(drm_fd, HUC_COPY_DATA_BUF_SIZE);
+		obj[2].handle = gem_create(drm_fd, 4096);
+
+		gem_write(drm_fd, obj[0].handle, 0, inputs, HUC_COPY_DATA_BUF_SIZE);
+
+		huc_copy(drm_fd, &obj[0], &obj[1], &obj[2]);
+		compare_huc_copy_result(drm_fd, obj[0].handle, obj[1].handle);
+	}
+
+	igt_fixture {
+		close(drm_fd);
+	}
+}
diff --git a/tests/meson.build b/tests/meson.build
index 570de545..0545b612 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -165,6 +165,7 @@ i915_progs = [
 	'gem_gtt_cpu_tlb',
 	'gem_gtt_hog',
 	'gem_gtt_speed',
+	'gem_huc_copy',
 	'gem_largeobject',
 	'gem_linear_blits',
 	'gem_lut_handle',
-- 
2.21.0.5.gaeb582a983

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-12-20 22:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19 23:50 [igt-dev] [PATCH i-g-t] tests/i915/gem_huc_copy: Enable a HuC copy test Robert M. Fosha
2019-12-20  0:34 ` [igt-dev] ✗ GitLab.Pipeline: warning for " Patchwork
2019-12-20  0:58 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2019-12-20 22:11 ` [igt-dev] [PATCH i-g-t] " Antonio Argenziano
2019-12-20 22:41 ` Robert M. Fosha [this message]
2019-12-23 22:19   ` [igt-dev] [PATCH i-g-t v3] " Robert M. Fosha
2020-01-10 17:41     ` [igt-dev] [PATCH i-g-t v4] " Robert M. Fosha
2020-01-10 18:28       ` Chris Wilson
2020-01-10 19:51         ` Ye, Tony
2020-01-10 19:54           ` Chris Wilson
2020-01-11  1:05             ` Ye, Tony
2020-01-16 23:56               ` Ye, Tony
2020-01-16 23:59                 ` Ye, Tony
2020-04-14 21:24       ` [igt-dev] [PATCH i-g-t v5] " Robert M. Fosha
2020-05-08 16:31         ` Argenziano, Antonio
2019-12-20 23:19 ` [igt-dev] ✗ GitLab.Pipeline: failure for tests/i915/gem_huc_copy: Enable a HuC copy test (rev2) Patchwork
2019-12-21  0:38 ` [igt-dev] ✗ Fi.CI.BAT: " Patchwork
2019-12-21  3:18 ` [igt-dev] ✓ Fi.CI.IGT: success for tests/i915/gem_huc_copy: Enable a HuC copy test Patchwork
2019-12-23 23:28 ` [igt-dev] ✗ Fi.CI.BAT: failure for tests/i915/gem_huc_copy: Enable a HuC copy test (rev3) Patchwork
2020-01-10 19:14 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/i915/gem_huc_copy: Enable a HuC copy test (rev4) Patchwork
2020-01-14 10:10 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2020-04-14 22:07 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/i915/gem_huc_copy: Enable a HuC copy test (rev5) Patchwork
2020-04-15 12:30 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2020-06-18 16:41 ` [igt-dev] [PATCH i-g-t v6] tests/i915/gem_huc_copy: Enable a HuC copy test Robert M. Fosha
2020-06-23 17:36   ` Argenziano, Antonio

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=20191220224135.4595-1-robert.m.fosha@intel.com \
    --to=robert.m.fosha@intel.com \
    --cc=feng.qi@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.