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>
29 * Testcase: Test the CS prefetch behaviour on batches
31 * Historically the batch prefetcher doesn't check whether it's crossing page
32 * boundaries and likes to throw up when it gets a pagefault in return for his
33 * over-eager behaviour. Check for this.
35 * This test for a bug where we've failed to plug a scratch pte entry into the
49 #include "ioctl_wrappers.h"
51 #include "intel_bufmgr.h"
52 #include "intel_batchbuffer.h"
54 #include "intel_chipset.h"
57 static drm_intel_bufmgr *bufmgr;
58 struct intel_batchbuffer *batch;
60 static void exec(int fd, uint32_t handle)
62 struct drm_i915_gem_execbuffer2 execbuf;
63 struct drm_i915_gem_exec_object2 gem_exec[1];
66 gem_exec[0].handle = handle;
67 gem_exec[0].relocation_count = 0;
68 gem_exec[0].relocs_ptr = 0;
69 gem_exec[0].alignment = 0;
70 gem_exec[0].offset = 0;
71 gem_exec[0].flags = 0;
72 gem_exec[0].rsvd1 = 0;
73 gem_exec[0].rsvd2 = 0;
75 execbuf.buffers_ptr = (uintptr_t)gem_exec;
76 execbuf.buffer_count = 1;
77 execbuf.batch_start_offset = 0;
78 execbuf.batch_len = 4096;
79 execbuf.cliprects_ptr = 0;
80 execbuf.num_cliprects = 0;
88 DRM_IOCTL_I915_GEM_EXECBUFFER2,
96 uint32_t batch_end[4] = {MI_BATCH_BUFFER_END, 0, 0, 0};
100 drm_intel_bo *sample_batch_bo;
102 igt_skip_on_simulation();
106 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
109 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
111 aper_size = gem_aperture_size(fd);
113 /* presume a big per-bo overhead */
114 igt_skip_on_f(intel_get_total_ram_mb() < (aper_size / (1024*1024)) * 3 / 2,
115 "not enough mem to run test\n");
117 count = aper_size / 4096;
119 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
122 sample_batch_bo = drm_intel_bo_alloc(bufmgr, "", 4096, 4096);
123 igt_assert(sample_batch_bo);
124 ret = drm_intel_bo_subdata(sample_batch_bo, 4096-sizeof(batch_end),
125 sizeof(batch_end), batch_end);
126 igt_assert(ret == 0);
128 /* fill the entire gart with batches and run them */
129 for (i = 0; i < count; i++) {
130 drm_intel_bo *batch_bo;
132 batch_bo = drm_intel_bo_alloc(bufmgr, "", 4096, 4096);
133 igt_assert(batch_bo);
135 /* copy the sample batch with the gpu to the new one, so that we
136 * also test the unmappable part of the gtt. */
137 BLIT_COPY_BATCH_START(batch->devid, 0);
138 OUT_BATCH((3 << 24) | /* 32 bits */
139 (0xcc << 16) | /* copy ROP */
141 OUT_BATCH(0); /* dst y1,x1 */
142 OUT_BATCH((1 << 16) | 1024);
143 OUT_RELOC(batch_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
144 BLIT_RELOC_UDW(batch->devid);
145 OUT_BATCH((0 << 16) | 0); /* src x1, y1 */
147 OUT_RELOC(sample_batch_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
148 BLIT_RELOC_UDW(batch->devid);
151 intel_batchbuffer_flush(batch);
153 gem_sync(fd, batch_bo->handle);
155 drm_intel_bo_disable_reuse(batch_bo);
157 /* launch the newly created batch */
158 exec(fd, batch_bo->handle);
161 //drm_intel_bo_unreference(batch_bo);
162 igt_progress("gem_cs_prefetch: ", i, count);
165 igt_info("Test suceeded, cleanup up - this might take a while.\n");
166 drm_intel_bufmgr_destroy(bufmgr);