blob: 5f0f33b871a7ee2efe3dc25b01dc8c700bff4b29 [file] [log] [blame]
Chris Wilson01acd702016-01-27 13:08:35 +00001/*
2 * Copyright © 2016 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#include "igt.h"
25
26IGT_TEST_DESCRIPTION("Basic sanity check of execbuf-ioctl rings.");
27
28static void noop(int fd, unsigned ring)
29{
30 uint32_t bbe = MI_BATCH_BUFFER_END;
31 struct drm_i915_gem_execbuffer2 execbuf;
32 struct drm_i915_gem_exec_object2 exec;
Chris Wilson01acd702016-01-27 13:08:35 +000033
34 gem_require_ring(fd, ring);
35
36 memset(&exec, 0, sizeof(exec));
37 exec.handle = gem_create(fd, 4096);
38 gem_write(fd, exec.handle, 0, &bbe, sizeof(bbe));
39
40 memset(&execbuf, 0, sizeof(execbuf));
41 execbuf.buffers_ptr = (uintptr_t)&exec;
42 execbuf.buffer_count = 1;
43 execbuf.flags = ring;
44 gem_execbuf(fd, &execbuf);
45 gem_close(fd, exec.handle);
46}
47
Chris Wilson95fbf7e2016-03-03 09:05:13 +000048static void readonly(int fd, unsigned ring)
49{
50 uint32_t bbe = MI_BATCH_BUFFER_END;
51 struct drm_i915_gem_execbuffer2 *execbuf;
52 struct drm_i915_gem_exec_object2 exec;
53
54 gem_require_ring(fd, ring);
55
56 memset(&exec, 0, sizeof(exec));
57 exec.handle = gem_create(fd, 4096);
58 gem_write(fd, exec.handle, 0, &bbe, sizeof(bbe));
59
60 execbuf = mmap(NULL, 4096, PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
61 igt_assert(execbuf != NULL);
62
63 execbuf->buffers_ptr = (uintptr_t)&exec;
64 execbuf->buffer_count = 1;
65 execbuf->flags = ring;
66 igt_assert(mprotect(execbuf, 4096, PROT_READ) == 0);
67
68 gem_execbuf(fd, execbuf);
69 munmap(execbuf, 4096);
70 gem_close(fd, exec.handle);
71}
72
73static void gtt(int fd, unsigned ring)
74{
75 uint32_t bbe = MI_BATCH_BUFFER_END;
76 struct drm_i915_gem_execbuffer2 *execbuf;
77 struct drm_i915_gem_exec_object2 *exec;
78 uint32_t handle;
79
80 gem_require_ring(fd, ring);
81
82 handle = gem_create(fd, 4096);
83
84 gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
85 execbuf = gem_mmap__gtt(fd, handle, 4096, PROT_WRITE);
86 exec = (struct drm_i915_gem_exec_object2 *)(execbuf + 1);
87 gem_close(fd, handle);
88
89 exec->handle = gem_create(fd, 4096);
90 gem_write(fd, exec->handle, 0, &bbe, sizeof(bbe));
91
92 execbuf->buffers_ptr = (uintptr_t)exec;
93 execbuf->buffer_count = 1;
94 execbuf->flags = ring;
95
96 gem_execbuf(fd, execbuf);
97 gem_close(fd, exec->handle);
98
99 munmap(execbuf, 4096);
100}
101
Chris Wilson01acd702016-01-27 13:08:35 +0000102igt_main
103{
104 const struct intel_execution_engine *e;
105 int fd = -1;
106
Daniel Vetterbe21fc02016-06-17 16:04:09 +0200107 igt_fixture {
Chris Wilson01acd702016-01-27 13:08:35 +0000108 fd = drm_open_driver(DRIVER_INTEL);
109
Daniel Vetterbe21fc02016-06-17 16:04:09 +0200110 igt_fork_hang_detector(fd);
111 }
Chris Wilson9d61a682016-03-25 18:22:54 +0000112
Chris Wilson95fbf7e2016-03-03 09:05:13 +0000113 for (e = intel_execution_engines; e->name; e++) {
Chris Wilson01acd702016-01-27 13:08:35 +0000114 igt_subtest_f("basic-%s", e->name)
115 noop(fd, e->exec_id | e->flags);
Chris Wilson95fbf7e2016-03-03 09:05:13 +0000116 igt_subtest_f("readonly-%s", e->name)
117 readonly(fd, e->exec_id | e->flags);
118 igt_subtest_f("gtt-%s", e->name)
119 gtt(fd, e->exec_id | e->flags);
120 }
Chris Wilson01acd702016-01-27 13:08:35 +0000121
Daniel Vetterbe21fc02016-06-17 16:04:09 +0200122 igt_fixture {
123 igt_stop_hang_detector();
Chris Wilson01acd702016-01-27 13:08:35 +0000124 close(fd);
Daniel Vetterbe21fc02016-06-17 16:04:09 +0200125 }
Chris Wilson01acd702016-01-27 13:08:35 +0000126}