2 * Copyright © 2011 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
24 * Daniel Vetter <daniel.vetter@ffwll.ch> (based on gem_storedw_*.c)
37 #include "ioctl_wrappers.h"
39 #include "intel_bufmgr.h"
40 #include "intel_batchbuffer.h"
43 #include "intel_chipset.h"
45 #define LOCAL_I915_EXEC_VEBOX (4<<0)
47 static drm_intel_bufmgr *bufmgr;
48 struct intel_batchbuffer *batch;
49 static drm_intel_bo *target_buffer;
53 static int mfd[NUM_FD];
54 static drm_intel_bufmgr *mbufmgr[NUM_FD];
55 static struct intel_batchbuffer *mbatch[NUM_FD];
56 static drm_intel_bo *mbuffer[NUM_FD];
59 * Testcase: Basic check of ring<->cpu sync using a dummy reloc
61 * The last test (that randomly switches the ring) seems to be pretty effective
62 * at hitting the missed irq bug that's worked around with the HWSTAM irq write.
66 #define MI_COND_BATCH_BUFFER_END (0x36<<23 | 1)
67 #define MI_DO_COMPARE (1<<21)
69 dummy_reloc_loop(int ring)
73 for (i = 0; i < 0x100000; i++) {
74 if (ring == I915_EXEC_RENDER) {
76 OUT_BATCH(MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE);
77 OUT_BATCH(0xffffffff); /* compare dword */
78 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER,
79 I915_GEM_DOMAIN_RENDER, 0);
84 OUT_BATCH(MI_FLUSH_DW | 1);
85 OUT_BATCH(0); /* reserved */
86 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER,
87 I915_GEM_DOMAIN_RENDER, 0);
88 OUT_BATCH(MI_NOOP | (1<<22) | (0xf));
91 intel_batchbuffer_flush_on_ring(batch, ring);
93 drm_intel_bo_map(target_buffer, 0);
94 // map to force completion
95 drm_intel_bo_unmap(target_buffer);
100 dummy_reloc_loop_random_ring(int num_rings)
106 for (i = 0; i < 0x100000; i++) {
107 int ring = random() % num_rings + 1;
109 if (ring == I915_EXEC_RENDER) {
111 OUT_BATCH(MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE);
112 OUT_BATCH(0xffffffff); /* compare dword */
113 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER,
114 I915_GEM_DOMAIN_RENDER, 0);
119 OUT_BATCH(MI_FLUSH_DW | 1);
120 OUT_BATCH(0); /* reserved */
121 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER,
122 I915_GEM_DOMAIN_RENDER, 0);
123 OUT_BATCH(MI_NOOP | (1<<22) | (0xf));
126 intel_batchbuffer_flush_on_ring(batch, ring);
128 drm_intel_bo_map(target_buffer, 0);
129 // map to force waiting on rendering
130 drm_intel_bo_unmap(target_buffer);
135 dummy_reloc_loop_random_ring_multi_fd(int num_rings)
138 struct intel_batchbuffer *saved_batch;
144 for (i = 0; i < 0x100000; i++) {
146 int ring = random() % num_rings + 1;
148 mindex = random() % NUM_FD;
149 batch = mbatch[mindex];
151 if (ring == I915_EXEC_RENDER) {
153 OUT_BATCH(MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE);
154 OUT_BATCH(0xffffffff); /* compare dword */
155 OUT_RELOC(mbuffer[mindex], I915_GEM_DOMAIN_RENDER,
156 I915_GEM_DOMAIN_RENDER, 0);
161 OUT_BATCH(MI_FLUSH_DW | 1);
162 OUT_BATCH(0); /* reserved */
163 OUT_RELOC(mbuffer[mindex], I915_GEM_DOMAIN_RENDER,
164 I915_GEM_DOMAIN_RENDER, 0);
165 OUT_BATCH(MI_NOOP | (1<<22) | (0xf));
168 intel_batchbuffer_flush_on_ring(batch, ring);
170 drm_intel_bo_map(target_buffer, 0);
171 // map to force waiting on rendering
172 drm_intel_bo_unmap(target_buffer);
184 igt_skip_on_simulation();
189 devid = intel_get_drm_devid(fd);
190 num_rings = gem_get_num_rings(fd);
191 /* Not yet implemented on pre-snb. */
192 igt_require(HAS_BLT_RING(devid));
194 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
196 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
198 batch = intel_batchbuffer_alloc(bufmgr, devid);
201 target_buffer = drm_intel_bo_alloc(bufmgr, "target bo", 4096, 4096);
202 igt_assert(target_buffer);
204 /* Create multi drm_fd and map one gem object to multi gem_contexts */
206 unsigned int target_flink;
207 char buffer_name[32];
208 igt_assert(dri_bo_flink(target_buffer, &target_flink) == 0);
210 for (i = 0; i < NUM_FD; i++) {
211 sprintf(buffer_name, "Target buffer %d\n", i);
212 mfd[i] = drm_open_any();
213 mbufmgr[i] = drm_intel_bufmgr_gem_init(mfd[i], 4096);
214 igt_assert_f(mbufmgr[i],
215 "fail to initialize buf manager "
218 drm_intel_bufmgr_gem_enable_reuse(mbufmgr[i]);
219 mbatch[i] = intel_batchbuffer_alloc(mbufmgr[i], devid);
220 igt_assert_f(mbatch[i],
221 "fail to create batchbuffer "
224 mbuffer[i] = intel_bo_gem_create_from_name(
228 igt_assert_f(mbuffer[i],
229 "fail to create gem bo from global "
230 "gem_handle %d for drm_fd %d\n",
231 target_flink, mfd[i]);
236 igt_subtest("render") {
237 igt_info("running dummy loop on render\n");
238 dummy_reloc_loop(I915_EXEC_RENDER);
239 igt_info("dummy loop run on render completed\n");
243 gem_require_ring(fd, I915_EXEC_BSD);
245 igt_info("running dummy loop on bsd\n");
246 dummy_reloc_loop(I915_EXEC_BSD);
247 igt_info("dummy loop run on bsd completed\n");
251 gem_require_ring(fd, I915_EXEC_BLT);
253 igt_info("running dummy loop on blt\n");
254 dummy_reloc_loop(I915_EXEC_BLT);
255 igt_info("dummy loop run on blt completed\n");
258 #ifdef I915_EXEC_VEBOX
259 igt_subtest("vebox") {
260 gem_require_ring(fd, I915_EXEC_VEBOX);
262 igt_info("running dummy loop on vebox\n");
263 dummy_reloc_loop(LOCAL_I915_EXEC_VEBOX);
264 igt_info("dummy loop run on vebox completed\n");
268 igt_subtest("mixed") {
271 igt_info("running dummy loop on random rings\n");
272 dummy_reloc_loop_random_ring(num_rings);
273 igt_info("dummy loop run on random rings completed\n");
276 igt_subtest("mixed_multi_fd") {
279 igt_info("running dummy loop on random rings based on "
281 dummy_reloc_loop_random_ring_multi_fd(num_rings);
282 igt_info("dummy loop run on random rings based on "
283 "multi drm_fd completed\n");
288 /* Free the buffer/batchbuffer/buffer mgr for multi-fd */
290 for (i = 0; i < NUM_FD; i++) {
291 dri_bo_unreference(mbuffer[i]);
292 intel_batchbuffer_free(mbatch[i]);
293 drm_intel_bufmgr_destroy(mbufmgr[i]);
297 drm_intel_bo_unreference(target_buffer);
298 intel_batchbuffer_free(batch);
299 drm_intel_bufmgr_destroy(bufmgr);