2 * Copyright © 2009 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 * Eric Anholt <eric@anholt.net>
25 * Jesse Barnes <jbarnes@virtuousgeek.org> (based on gem_bad_blit.c)
38 #include "ioctl_wrappers.h"
40 #include "intel_bufmgr.h"
41 #include "intel_chipset.h"
42 #include "intel_batchbuffer.h"
45 static drm_intel_bufmgr *bufmgr;
46 static drm_intel_bo *target_bo;
47 static int has_ppgtt = 0;
49 #define SECURE_DISPATCH (1<<0)
51 /* Like the store dword test, but we create new command buffers each time */
53 store_dword_loop(int divider, unsigned flags)
59 igt_info("running storedw loop with stall every %i batch\n", divider);
61 cmd = MI_STORE_DWORD_IMM;
63 cmd |= MI_MEM_VIRTUAL;
65 for (i = 0; i < SLOW_QUICK(0x2000, 4); i++) {
67 int cmd_address_offset;
68 cmd_bo = drm_intel_bo_alloc(bufmgr, "cmd bo", 4096, 4096);
71 /* Upload through cpu mmaps to make sure we don't have a gtt
72 * mapping which could paper over secure batch submission
73 * failing to bind that. */
74 drm_intel_bo_map(cmd_bo, 1);
75 buf = cmd_bo->virtual;
78 if (intel_gen(drm_intel_bufmgr_gem_get_devid(bufmgr)) >= 8) {
79 cmd_address_offset = j * 4;
80 buf[j++] = target_bo->offset;
84 cmd_address_offset = j * 4;
85 buf[j++] = target_bo->offset;
88 buf[j++] = 0x42000000 + val;
90 igt_assert(drm_intel_bo_references(cmd_bo, target_bo) == 0);
92 igt_assert(drm_intel_bo_emit_reloc(cmd_bo, cmd_address_offset, target_bo, 0,
93 I915_GEM_DOMAIN_INSTRUCTION,
94 I915_GEM_DOMAIN_INSTRUCTION) == 0);
95 buf[j++] = MI_BATCH_BUFFER_END;
96 buf[j++] = MI_BATCH_BUFFER_END;
98 drm_intel_bo_unmap(cmd_bo);
100 igt_assert(drm_intel_bo_references(cmd_bo, target_bo) == 1);
102 #define LOCAL_I915_EXEC_SECURE (1<<9)
103 igt_assert(drm_intel_bo_mrb_exec(cmd_bo, j * 4, NULL, 0, 0,
105 (flags & SECURE_DISPATCH ? LOCAL_I915_EXEC_SECURE : 0))
108 if (i % divider != 0)
111 drm_intel_bo_wait_rendering(cmd_bo);
113 drm_intel_bo_map(target_bo, 1);
115 buf = target_bo->virtual;
116 igt_assert_f(buf[0] == (0x42000000 | val),
117 "value mismatch: cur 0x%08x, stored 0x%08x\n",
118 buf[0], 0x42000000 | val);
120 buf[0] = 0; /* let batch write it again */
121 drm_intel_bo_unmap(target_bo);
124 drm_intel_bo_unreference(cmd_bo);
129 igt_info("completed %d writes successfully\n", i);
137 igt_skip_on_simulation();
141 devid = intel_get_drm_devid(fd);
143 has_ppgtt = gem_uses_aliasing_ppgtt(fd);
145 /* storedw needs gtt address on gen4+/g33 and snoopable memory.
146 * Strictly speaking we could implement this now ... */
147 igt_require(intel_gen(devid) >= 6);
149 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
152 // drm_intel_bufmgr_gem_enable_reuse(bufmgr);
154 target_bo = drm_intel_bo_alloc(bufmgr, "target bo", 4096, 4096);
155 igt_assert(target_bo);
158 igt_subtest("normal") {
159 store_dword_loop(1, 0);
160 store_dword_loop(2, 0);
161 store_dword_loop(3, 0);
162 store_dword_loop(5, 0);
165 igt_subtest("secure-dispatch") {
166 store_dword_loop(1, SECURE_DISPATCH);
167 store_dword_loop(2, SECURE_DISPATCH);
168 store_dword_loop(3, SECURE_DISPATCH);
169 store_dword_loop(5, SECURE_DISPATCH);
173 drm_intel_bo_unreference(target_bo);
174 drm_intel_bufmgr_destroy(bufmgr);