2 * Copyright © 2012 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>
25 * Chris Wilson <chris@chris-wilson.co.uk>
40 #include "ioctl_wrappers.h"
42 #include "intel_bufmgr.h"
43 #include "intel_batchbuffer.h"
45 #include "intel_chipset.h"
49 * Testcase: snoop consistency when touching partial cachelines
53 static drm_intel_bufmgr *bufmgr;
54 struct intel_batchbuffer *batch;
56 drm_intel_bo *scratch_bo;
57 drm_intel_bo *staging_bo;
58 #define BO_SIZE (4*4096)
60 uint64_t mappable_gtt_limit;
64 copy_bo(drm_intel_bo *src, drm_intel_bo *dst)
66 BLIT_COPY_BATCH_START(devid, 0);
67 OUT_BATCH((3 << 24) | /* 32 bits */
68 (0xcc << 16) | /* copy ROP */
70 OUT_BATCH(0 << 16 | 0);
71 OUT_BATCH((BO_SIZE/4096) << 16 | 1024);
72 OUT_RELOC_FENCED(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
73 OUT_BATCH(0 << 16 | 0);
75 OUT_RELOC_FENCED(src, I915_GEM_DOMAIN_RENDER, 0, 0);
78 intel_batchbuffer_flush(batch);
82 blt_bo_fill(drm_intel_bo *tmp_bo, drm_intel_bo *bo, uint8_t val)
87 do_or_die(drm_intel_gem_bo_map_gtt(tmp_bo));
88 gtt_ptr = tmp_bo->virtual;
90 for (i = 0; i < BO_SIZE; i++)
93 drm_intel_gem_bo_unmap_gtt(tmp_bo);
95 if (bo->offset < mappable_gtt_limit &&
96 (IS_G33(devid) || intel_gen(devid) >= 4))
102 #define MAX_BLT_SIZE 128
104 #define TEST_READ 0x1
105 #define TEST_WRITE 0x2
106 #define TEST_BOTH (TEST_READ | TEST_WRITE)
109 unsigned flags = TEST_BOTH;
114 igt_skip_on_simulation();
121 gem_require_caching(fd);
123 devid = intel_get_drm_devid(fd);
124 if (IS_GEN2(devid)) /* chipset only handles cached -> uncached */
126 if (IS_BROADWATER(devid) || IS_CRESTLINE(devid)) {
127 /* chipset is completely fubar */
128 igt_info("coherency broken on i965g/gm\n");
132 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
133 batch = intel_batchbuffer_alloc(bufmgr, devid);
135 /* overallocate the buffers we're actually using because */
136 scratch_bo = drm_intel_bo_alloc(bufmgr, "scratch bo", BO_SIZE, 4096);
137 gem_set_caching(fd, scratch_bo->handle, 1);
139 staging_bo = drm_intel_bo_alloc(bufmgr, "staging bo", BO_SIZE, 4096);
141 igt_init_aperture_trashers(bufmgr);
142 mappable_gtt_limit = gem_mappable_aperture_size();
145 igt_subtest("reads") {
146 igt_require(flags & TEST_READ);
148 igt_info("checking partial reads\n");
150 for (i = 0; i < ROUNDS; i++) {
154 blt_bo_fill(staging_bo, scratch_bo, i);
156 start = random() % BO_SIZE;
157 len = random() % (BO_SIZE-start) + 1;
159 drm_intel_bo_map(scratch_bo, false);
160 cpu_ptr = scratch_bo->virtual;
161 for (j = 0; j < len; j++) {
162 igt_assert_f(cpu_ptr[j] == val0,
163 "mismatch at %i, got: %i, expected: %i\n",
164 j, cpu_ptr[j], val0);
166 drm_intel_bo_unmap(scratch_bo);
168 igt_progress("partial reads test: ", i, ROUNDS);
172 igt_subtest("writes") {
173 igt_require(flags & TEST_WRITE);
175 igt_info("checking partial writes\n");
177 for (i = 0; i < ROUNDS; i++) {
178 uint8_t val0 = i, val1;
181 blt_bo_fill(staging_bo, scratch_bo, val0);
183 start = random() % BO_SIZE;
184 len = random() % (BO_SIZE-start) + 1;
187 drm_intel_bo_map(scratch_bo, true);
188 cpu_ptr = scratch_bo->virtual;
189 memset(cpu_ptr + start, val1, len);
190 drm_intel_bo_unmap(scratch_bo);
192 copy_bo(scratch_bo, staging_bo);
193 do_or_die(drm_intel_gem_bo_map_gtt(staging_bo));
194 gtt_ptr = staging_bo->virtual;
196 for (j = 0; j < start; j++) {
197 igt_assert_f(gtt_ptr[j] == val0,
198 "mismatch at %i, partial=[%d+%d] got: %i, expected: %i\n",
199 j, start, len, gtt_ptr[j], val0);
201 for (; j < start + len; j++) {
202 igt_assert_f(gtt_ptr[j] == val1,
203 "mismatch at %i, partial=[%d+%d] got: %i, expected: %i\n",
204 j, start, len, gtt_ptr[j], val1);
206 for (; j < BO_SIZE; j++) {
207 igt_assert_f(gtt_ptr[j] == val0,
208 "mismatch at %i, partial=[%d+%d] got: %i, expected: %i\n",
209 j, start, len, gtt_ptr[j], val0);
211 drm_intel_gem_bo_unmap_gtt(staging_bo);
213 igt_progress("partial writes test: ", i, ROUNDS);
217 igt_subtest("read-writes") {
218 igt_require((flags & TEST_BOTH) == TEST_BOTH);
220 igt_info("checking partial writes after partial reads\n");
222 for (i = 0; i < ROUNDS; i++) {
223 uint8_t val0 = i, val1, val2;
226 blt_bo_fill(staging_bo, scratch_bo, val0);
229 start = random() % BO_SIZE;
230 len = random() % (BO_SIZE-start) + 1;
232 do_or_die(drm_intel_bo_map(scratch_bo, false));
233 cpu_ptr = scratch_bo->virtual;
234 for (j = 0; j < len; j++) {
235 igt_assert_f(cpu_ptr[j] == val0,
236 "mismatch in read at %i, got: %i, expected: %i\n",
237 j, cpu_ptr[j], val0);
239 drm_intel_bo_unmap(scratch_bo);
241 /* Change contents through gtt to make the pread cachelines
244 blt_bo_fill(staging_bo, scratch_bo, val1);
247 start = random() % BO_SIZE;
248 len = random() % (BO_SIZE-start) + 1;
251 do_or_die(drm_intel_bo_map(scratch_bo, false));
252 cpu_ptr = scratch_bo->virtual;
253 memset(cpu_ptr + start, val2, len);
255 copy_bo(scratch_bo, staging_bo);
256 do_or_die(drm_intel_gem_bo_map_gtt(staging_bo));
257 gtt_ptr = staging_bo->virtual;
259 for (j = 0; j < start; j++) {
260 igt_assert_f(gtt_ptr[j] == val1,
261 "mismatch at %i, partial=[%d+%d] got: %i, expected: %i\n",
262 j, start, len, gtt_ptr[j], val1);
264 for (; j < start + len; j++) {
265 igt_assert_f(gtt_ptr[j] == val2,
266 "mismatch at %i, partial=[%d+%d] got: %i, expected: %i\n",
267 j, start, len, gtt_ptr[j], val2);
269 for (; j < BO_SIZE; j++) {
270 igt_assert_f(gtt_ptr[j] == val1,
271 "mismatch at %i, partial=[%d+%d] got: %i, expected: %i\n",
272 j, start, len, gtt_ptr[j], val1);
274 drm_intel_gem_bo_unmap_gtt(staging_bo);
275 drm_intel_bo_unmap(scratch_bo);
277 igt_progress("partial read/writes test: ", i, ROUNDS);
282 igt_cleanup_aperture_trashers();
283 drm_intel_bufmgr_destroy(bufmgr);