2 * Copyright © 2013 Intel Corporation
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:
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
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
33 #include "ioctl_wrappers.h"
34 #include "intel_chipset.h"
36 #ifndef I915_PARAM_CMD_PARSER_VERSION
37 #define I915_PARAM_CMD_PARSER_VERSION 28
40 static int __gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
42 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf))
48 static void exec_batch_patched(int fd, uint32_t cmd_bo, uint32_t *cmds,
49 int size, int patch_offset, uint64_t expected_value)
51 struct drm_i915_gem_execbuffer2 execbuf;
52 struct drm_i915_gem_exec_object2 objs[2];
53 struct drm_i915_gem_relocation_entry reloc[1];
55 uint32_t target_bo = gem_create(fd, 4096);
56 uint64_t actual_value = 0;
58 gem_write(fd, cmd_bo, 0, cmds, size);
60 reloc[0].offset = patch_offset;
62 reloc[0].target_handle = target_bo;
63 reloc[0].read_domains = I915_GEM_DOMAIN_RENDER;
64 reloc[0].write_domain = I915_GEM_DOMAIN_RENDER;
65 reloc[0].presumed_offset = 0;
67 objs[0].handle = target_bo;
68 objs[0].relocation_count = 0;
69 objs[0].relocs_ptr = 0;
70 objs[0].alignment = 0;
76 objs[1].handle = cmd_bo;
77 objs[1].relocation_count = 1;
78 objs[1].relocs_ptr = (uintptr_t)reloc;
79 objs[1].alignment = 0;
85 execbuf.buffers_ptr = (uintptr_t)objs;
86 execbuf.buffer_count = 2;
87 execbuf.batch_start_offset = 0;
88 execbuf.batch_len = size;
89 execbuf.cliprects_ptr = 0;
90 execbuf.num_cliprects = 0;
93 execbuf.flags = I915_EXEC_RENDER;
94 i915_execbuffer2_set_context_id(execbuf, 0);
97 gem_execbuf(fd, &execbuf);
100 gem_read(fd,target_bo, 0, &actual_value, sizeof(actual_value));
101 igt_assert_eq(expected_value, actual_value);
103 gem_close(fd, target_bo);
106 static void exec_batch(int fd, uint32_t cmd_bo, uint32_t *cmds,
107 int size, int ring, int expected_ret)
109 struct drm_i915_gem_execbuffer2 execbuf;
110 struct drm_i915_gem_exec_object2 objs[1];
112 gem_write(fd, cmd_bo, 0, cmds, size);
114 objs[0].handle = cmd_bo;
115 objs[0].relocation_count = 0;
116 objs[0].relocs_ptr = 0;
117 objs[0].alignment = 0;
123 execbuf.buffers_ptr = (uintptr_t)objs;
124 execbuf.buffer_count = 1;
125 execbuf.batch_start_offset = 0;
126 execbuf.batch_len = size;
127 execbuf.cliprects_ptr = 0;
128 execbuf.num_cliprects = 0;
131 execbuf.flags = ring;
132 i915_execbuffer2_set_context_id(execbuf, 0);
135 igt_assert_eq(__gem_execbuf(fd, &execbuf), expected_ret);
137 gem_sync(fd, cmd_bo);
140 static void exec_split_batch(int fd, uint32_t *cmds,
141 int size, int ring, int expected_ret)
143 struct drm_i915_gem_execbuffer2 execbuf;
144 struct drm_i915_gem_exec_object2 objs[1];
146 uint32_t noop[1024] = { 0 };
148 // Allocate and fill a 2-page batch with noops
149 cmd_bo = gem_create(fd, 4096 * 2);
150 gem_write(fd, cmd_bo, 0, noop, sizeof(noop));
151 gem_write(fd, cmd_bo, 4096, noop, sizeof(noop));
153 // Write the provided commands such that the first dword
154 // of the command buffer is the last dword of the first
155 // page (i.e. the command is split across the two pages).
156 gem_write(fd, cmd_bo, 4096-sizeof(uint32_t), cmds, size);
158 objs[0].handle = cmd_bo;
159 objs[0].relocation_count = 0;
160 objs[0].relocs_ptr = 0;
161 objs[0].alignment = 0;
167 execbuf.buffers_ptr = (uintptr_t)objs;
168 execbuf.buffer_count = 1;
169 execbuf.batch_start_offset = 0;
170 execbuf.batch_len = size;
171 execbuf.cliprects_ptr = 0;
172 execbuf.num_cliprects = 0;
175 execbuf.flags = ring;
176 i915_execbuffer2_set_context_id(execbuf, 0);
179 igt_assert_eq(__gem_execbuf(fd, &execbuf), expected_ret);
181 gem_sync(fd, cmd_bo);
182 gem_close(fd, cmd_bo);
188 #define MI_ARB_ON_OFF (0x8 << 23)
189 #define MI_DISPLAY_FLIP ((0x14 << 23) | 1)
190 #define MI_LOAD_REGISTER_IMM ((0x22 << 23) | 1)
192 #define GFX_OP_PIPE_CONTROL ((0x3<<29)|(0x3<<27)|(0x2<<24)|2)
193 #define PIPE_CONTROL_QW_WRITE (1<<14)
194 #define PIPE_CONTROL_LRI_POST_OP (1<<23)
196 #define OACONTROL 0x2360
201 int parser_version = 0;
202 drm_i915_getparam_t gp;
207 gp.param = I915_PARAM_CMD_PARSER_VERSION;
208 gp.value = &parser_version;
209 rc = drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
210 igt_require(!rc && parser_version > 0);
212 igt_require(gem_uses_aliasing_ppgtt(fd));
214 handle = gem_create(fd, 4096);
216 /* ATM cmd parser only exists on gen7. */
217 igt_require(intel_gen(intel_get_drm_devid(fd)) == 7);
220 igt_subtest("basic-allowed") {
223 PIPE_CONTROL_QW_WRITE,
229 exec_batch_patched(fd, handle,
235 igt_subtest("basic-rejected") {
236 uint32_t arb_on_off[] = {
240 uint32_t display_flip[] = {
246 exec_batch(fd, handle,
247 arb_on_off, sizeof(arb_on_off),
250 exec_batch(fd, handle,
251 arb_on_off, sizeof(arb_on_off),
254 if (gem_has_vebox(fd)) {
255 exec_batch(fd, handle,
256 arb_on_off, sizeof(arb_on_off),
260 exec_batch(fd, handle,
261 display_flip, sizeof(display_flip),
266 igt_subtest("registers") {
267 uint32_t lri_bad[] = {
268 MI_LOAD_REGISTER_IMM,
269 0, // disallowed register address
273 uint32_t lri_ok[] = {
274 MI_LOAD_REGISTER_IMM,
275 0x5280, // allowed register address (SO_WRITE_OFFSET[0])
279 exec_batch(fd, handle,
280 lri_bad, sizeof(lri_bad),
283 exec_batch(fd, handle,
284 lri_ok, sizeof(lri_ok),
289 igt_subtest("bitmasks") {
292 (PIPE_CONTROL_QW_WRITE |
293 PIPE_CONTROL_LRI_POST_OP),
299 exec_batch(fd, handle,
305 igt_subtest("batch-without-end") {
306 uint32_t noop[1024] = { 0 };
307 exec_batch(fd, handle,
313 igt_subtest("cmd-crossing-page") {
314 uint32_t lri_ok[] = {
315 MI_LOAD_REGISTER_IMM,
316 0x5280, // allowed register address (SO_WRITE_OFFSET[0])
321 lri_ok, sizeof(lri_ok),
326 igt_subtest("oacontrol-tracking") {
327 uint32_t lri_ok[] = {
328 MI_LOAD_REGISTER_IMM,
331 MI_LOAD_REGISTER_IMM,
337 uint32_t lri_bad[] = {
338 MI_LOAD_REGISTER_IMM,
343 uint32_t lri_extra_bad[] = {
344 MI_LOAD_REGISTER_IMM,
347 MI_LOAD_REGISTER_IMM,
350 MI_LOAD_REGISTER_IMM,
355 exec_batch(fd, handle,
356 lri_ok, sizeof(lri_ok),
359 exec_batch(fd, handle,
360 lri_bad, sizeof(lri_bad),
363 exec_batch(fd, handle,
364 lri_extra_bad, sizeof(lri_extra_bad),
370 gem_close(fd, handle);