gem_pipe_control_store_loop.c 5.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
 * Copyright © 2011 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Authors:
 *    Daniel Vetter <daniel.vetter@ffwll.ch> (based on gem_storedw_*.c)
 *
 */

/*
 * Testcase: (TLB-)Coherency of pipe_control QW writes
 *
 * Writes a counter-value into an always newly allocated target bo (by disabling
 * buffer reuse). Decently trashes on tlb inconsistencies, too.
 */
34
#include "igt.h"
35 36 37 38 39 40 41 42 43 44 45
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include "drm.h"
#include "intel_bufmgr.h"

46 47
IGT_TEST_DESCRIPTION("Test (TLB-)Coherency of pipe_control QW writes.");

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
static drm_intel_bufmgr *bufmgr;
struct intel_batchbuffer *batch;
uint32_t devid;

#define GFX_OP_PIPE_CONTROL	((0x3<<29)|(0x3<<27)|(0x2<<24)|2)
#define   PIPE_CONTROL_WRITE_IMMEDIATE	(1<<14)
#define   PIPE_CONTROL_WRITE_TIMESTAMP	(3<<14)
#define   PIPE_CONTROL_DEPTH_STALL (1<<13)
#define   PIPE_CONTROL_WC_FLUSH	(1<<12)
#define   PIPE_CONTROL_IS_FLUSH	(1<<11) /* MBZ on Ironlake */
#define   PIPE_CONTROL_TC_FLUSH (1<<10) /* GM45+ only */
#define   PIPE_CONTROL_STALL_AT_SCOREBOARD (1<<1)
#define   PIPE_CONTROL_CS_STALL	(1<<20)
#define   PIPE_CONTROL_GLOBAL_GTT (1<<2) /* in addr dword */

/* Like the store dword test, but we create new command buffers each time */
static void
65
store_pipe_control_loop(bool preuse_buffer)
66 67 68 69 70
{
	int i, val = 0;
	uint32_t *buf;
	drm_intel_bo *target_bo;

71
	for (i = 0; i < SLOW_QUICK(0x10000, 4); i++) {
72 73 74
		/* we want to check tlb consistency of the pipe_control target,
		 * so get a new buffer every time around */
		target_bo = drm_intel_bo_alloc(bufmgr, "target bo", 4096, 4096);
75
		igt_assert(target_bo);
76

77
		if (preuse_buffer) {
78
			COLOR_BLIT_COPY_BATCH_START(0);
79 80 81 82 83 84 85 86 87
			OUT_BATCH((3 << 24) | (0xf0 << 16) | 64);
			OUT_BATCH(0);
			OUT_BATCH(1 << 16 | 1);

			/*
			 * IMPORTANT: We need to preuse the buffer in a
			 * different domain than what the pipe control write
			 * (and kernel wa) uses!
			 */
88
			OUT_RELOC_FENCED(target_bo,
89 90 91 92 93 94
			     I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
			     0);
			OUT_BATCH(0xdeadbeef);
			ADVANCE_BATCH();

			intel_batchbuffer_flush(batch);
95
		}
96

97 98 99
		/* gem_storedw_batches_loop.c is a bit overenthusiastic with
		 * creating new batchbuffers - with buffer reuse disabled, the
		 * support code will do that for us. */
100 101
		if (batch->gen >= 8) {
			BEGIN_BATCH(4, 1);
102 103
			OUT_BATCH(GFX_OP_PIPE_CONTROL + 1);
			OUT_BATCH(PIPE_CONTROL_WRITE_IMMEDIATE);
104
			OUT_RELOC_FENCED(target_bo,
105 106 107 108 109
			     I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
			     PIPE_CONTROL_GLOBAL_GTT);
			OUT_BATCH(val); /* write data */
			ADVANCE_BATCH();

110
		} else if (batch->gen >= 6) {
111 112
			/* work-around hw issue, see intel_emit_post_sync_nonzero_flush
			 * in mesa sources. */
113
			BEGIN_BATCH(4, 1);
114 115 116 117 118 119 120
			OUT_BATCH(GFX_OP_PIPE_CONTROL);
			OUT_BATCH(PIPE_CONTROL_CS_STALL |
			     PIPE_CONTROL_STALL_AT_SCOREBOARD);
			OUT_BATCH(0); /* address */
			OUT_BATCH(0); /* write data */
			ADVANCE_BATCH();

121
			BEGIN_BATCH(4, 1);
122 123 124 125 126 127 128
			OUT_BATCH(GFX_OP_PIPE_CONTROL);
			OUT_BATCH(PIPE_CONTROL_WRITE_IMMEDIATE);
			OUT_RELOC(target_bo,
			     I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION, 
			     PIPE_CONTROL_GLOBAL_GTT);
			OUT_BATCH(val); /* write data */
			ADVANCE_BATCH();
129 130
		} else if (batch->gen >= 4) {
			BEGIN_BATCH(4, 1);
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
			OUT_BATCH(GFX_OP_PIPE_CONTROL | PIPE_CONTROL_WC_FLUSH |
					PIPE_CONTROL_TC_FLUSH |
					PIPE_CONTROL_WRITE_IMMEDIATE | 2);
			OUT_RELOC(target_bo,
				I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
				PIPE_CONTROL_GLOBAL_GTT);
			OUT_BATCH(val);
			OUT_BATCH(0xdeadbeef);
			ADVANCE_BATCH();
		}

		intel_batchbuffer_flush_on_ring(batch, 0);

		drm_intel_bo_map(target_bo, 1);

		buf = target_bo->virtual;
147
		igt_assert(buf[0] == val);
148

149 150 151
		drm_intel_bo_unmap(target_bo);
		/* Make doublesure that this buffer won't get reused. */
		drm_intel_bo_disable_reuse(target_bo);
152 153 154 155 156 157
		drm_intel_bo_unreference(target_bo);

		val++;
	}
}

158 159
int fd;

Daniel Vetter's avatar
Daniel Vetter committed
160
igt_main
161
{
162
	igt_fixture {
163
		fd = drm_open_driver(DRIVER_INTEL);
164 165
		igt_require_gem(fd);

166
		devid = intel_get_drm_devid(fd);
167

168 169
		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
		igt_assert(bufmgr);
170

171 172
		igt_skip_on(IS_GEN2(devid) || IS_GEN3(devid));
		igt_skip_on(devid == PCI_CHIP_I965_G); /* has totally broken pipe control */
173

174 175 176 177 178 179 180
		/* IMPORTANT: No call to
		 * drm_intel_bufmgr_gem_enable_reuse(bufmgr);
		 * here because we wan't to have fresh buffers (to trash the tlb)
		 * every time! */

		batch = intel_batchbuffer_alloc(bufmgr, devid);
		igt_assert(batch);
181 182
	}

183 184
	igt_subtest("fresh-buffer")
		store_pipe_control_loop(false);
185

186 187
	igt_subtest("reused-buffer")
		store_pipe_control_loop(true);
188

189 190 191 192 193 194
	igt_fixture {
		intel_batchbuffer_free(batch);
		drm_intel_bufmgr_destroy(bufmgr);

		close(fd);
	}
195
}