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)
40 #include "intel_bufmgr.h"
41 #include "intel_batchbuffer.h"
42 #include "intel_gpu_tools.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;
52 * Testcase: Basic check of ring<->cpu sync using a dummy reloc
54 * The last test (that randomly switches the ring) seems to be pretty effective
55 * at hitting the missed irq bug that's worked around with the HWSTAM irq write.
59 #define MI_COND_BATCH_BUFFER_END (0x36<<23 | 1)
60 #define MI_DO_COMPARE (1<<21)
62 dummy_reloc_loop(int ring)
66 for (i = 0; i < 0x100000; i++) {
67 if (ring == I915_EXEC_RENDER) {
69 OUT_BATCH(MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE);
70 OUT_BATCH(0xffffffff); /* compare dword */
71 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER,
72 I915_GEM_DOMAIN_RENDER, 0);
77 OUT_BATCH(MI_FLUSH_DW | 1);
78 OUT_BATCH(0); /* reserved */
79 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER,
80 I915_GEM_DOMAIN_RENDER, 0);
81 OUT_BATCH(MI_NOOP | (1<<22) | (0xf));
84 intel_batchbuffer_flush_on_ring(batch, ring);
86 drm_intel_bo_map(target_buffer, 0);
87 // map to force completion
88 drm_intel_bo_unmap(target_buffer);
93 dummy_reloc_loop_random_ring(int num_rings)
99 for (i = 0; i < 0x100000; i++) {
100 int ring = random() % num_rings + 1;
102 if (ring == I915_EXEC_RENDER) {
104 OUT_BATCH(MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE);
105 OUT_BATCH(0xffffffff); /* compare dword */
106 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER,
107 I915_GEM_DOMAIN_RENDER, 0);
112 OUT_BATCH(MI_FLUSH_DW | 1);
113 OUT_BATCH(0); /* reserved */
114 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER,
115 I915_GEM_DOMAIN_RENDER, 0);
116 OUT_BATCH(MI_NOOP | (1<<22) | (0xf));
119 intel_batchbuffer_flush_on_ring(batch, ring);
121 drm_intel_bo_map(target_buffer, 0);
122 // map to force waiting on rendering
123 drm_intel_bo_unmap(target_buffer);
127 int main(int argc, char **argv)
133 drmtest_subtest_init(argc, argv);
134 drmtest_skip_on_simulation();
137 devid = intel_get_drm_devid(fd);
138 num_rings = gem_get_num_rings(fd);
139 if (!HAS_BLT_RING(devid)) {
140 fprintf(stderr, "not (yet) implemented for pre-snb\n");
144 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
146 fprintf(stderr, "failed to init libdrm\n");
149 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
151 batch = intel_batchbuffer_alloc(bufmgr, devid);
153 fprintf(stderr, "failed to create batch buffer\n");
157 target_buffer = drm_intel_bo_alloc(bufmgr, "target bo", 4096, 4096);
158 if (!target_buffer) {
159 fprintf(stderr, "failed to alloc target buffer\n");
163 if (drmtest_run_subtest("render")) {
164 printf("running dummy loop on render\n");
165 dummy_reloc_loop(I915_EXEC_RENDER);
166 printf("dummy loop run on render completed\n");
169 if (drmtest_run_subtest("bsd")) {
170 if (HAS_BSD_RING(devid)) {
172 printf("running dummy loop on bsd\n");
173 dummy_reloc_loop(I915_EXEC_BSD);
174 printf("dummy loop run on bsd completed\n");
178 if (drmtest_run_subtest("blt")) {
179 if (HAS_BLT_RING(devid)) {
181 printf("running dummy loop on blt\n");
182 dummy_reloc_loop(I915_EXEC_BLT);
183 printf("dummy loop run on blt completed\n");
187 if (drmtest_run_subtest("vebox")) {
188 if (gem_has_vebox(fd)) {
190 printf("running dummy loop on vebox\n");
191 dummy_reloc_loop(LOCAL_I915_EXEC_VEBOX);
192 printf("dummy loop run on vebox completed\n");
196 if (drmtest_run_subtest("mixed")) {
199 printf("running dummy loop on random rings\n");
200 dummy_reloc_loop_random_ring(num_rings);
201 printf("dummy loop run on random rings completed\n");
205 drm_intel_bo_unreference(target_buffer);
206 intel_batchbuffer_free(batch);
207 drm_intel_bufmgr_destroy(bufmgr);