blob: b0a4cda24e85b5d528244d99c9624b22f8fd28dd [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
107 igt_fixture
108 fd = drm_open_driver(DRIVER_INTEL);
109
Chris Wilson9d61a682016-03-25 18:22:54 +0000110 igt_fork_hang_detector(fd);
111
Chris Wilson95fbf7e2016-03-03 09:05:13 +0000112 for (e = intel_execution_engines; e->name; e++) {
Chris Wilson01acd702016-01-27 13:08:35 +0000113 igt_subtest_f("basic-%s", e->name)
114 noop(fd, e->exec_id | e->flags);
Chris Wilson95fbf7e2016-03-03 09:05:13 +0000115 igt_subtest_f("readonly-%s", e->name)
116 readonly(fd, e->exec_id | e->flags);
117 igt_subtest_f("gtt-%s", e->name)
118 gtt(fd, e->exec_id | e->flags);
119 }
Chris Wilson01acd702016-01-27 13:08:35 +0000120
Chris Wilson9d61a682016-03-25 18:22:54 +0000121 igt_stop_hang_detector();
122
Chris Wilson01acd702016-01-27 13:08:35 +0000123 igt_fixture
124 close(fd);
125}